Full Version: setfocus to next available field
UtterAccess Forums > Microsoft® Access > Access Forms
dmfrog
Hi
I am trying to manage a form that has multiple options based on the selections the user makes. The form allows users to enter a request for a job to be performed.
There are two 'parts' to the form - top part asks the user for the type of job (eg - electrical, plumbing, etc). Once the user selects a trade they select a priority (urgent, within 2 days, etc). Once both selections have been made, the form needs to lock those two fields and open up various fields in the lower part of the form. Each trade has different options so I dfo not know ahead of time which field will be the next open field to setfocus to so I can lock the top two fields.
Otried this to try and work through the form controls to locate the next open field, remebering I have to ignore the top two:
Dim ctl As Access.Control
For Each ctl In frm

If Not (ctl.Locked = True) Then
With ctl
.SetFocus
End With
Exit For
End If
Next ctl
But Locked is not an availabe parameter for ctl.
Thanks for your help in advance
DM.
fkegley
How hard would it be to develop separate forms with exactly the fields you need for each trade, then change the Source Object of the subform control to the appropriate form?
ocked may not be a property of ALL controls on a form. Therefore, your loop will fail.
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then ' I am not sure this syntax is correct
IF ctl.Locked = False Then
ctl.SetFocus
Exit For
End If
Next ctl
Also, just because it doesn't appear in the dropdown list, it doesn't, for a generic list, doesn't mean you can't use it.
dmfrog
Hi Frank
Thanks for the thoughts and code. I hadn't considered having a separate screen for each trade - but that sounds like a good idea. I'll see how easy it would be. The code you suggested worked like a charm. Thank you
DM
fkegley
DM, you're welcome. I am glad I could help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.