How do I programmatically set focus to the first control in the tab order

  • Thread starter Thread starter ambradnum
  • Start date Start date
A

ambradnum

I have a subform that is used by many different 'parent' forms.

The tabbing works fine in that the subform gets the focus and then each
control gets focus in turn. However when the last control in the
subform loses focus the first control in the subform gets focus.

I want to set focus to the first enabled control in the tab order in
the 'parent' form.

How do I do that?

TIA
Alan
 
Alan,

On the Exit event of the last control of the subform, put code like this...
Me.Parent.Controls(0).SetFocus
 
Or, even better, since it picks up where you left off, teach your user that:
"To move the focus outside a subform control, press CTRL+TAB."
 
Thanks, Steve - I tried this but unfortunately it didn't work.
It appears controls(0) is not always the first in the Tab Order
but just the first one created.
 
Alan

As far as I know, there is not instantaneous way to identify the first
control in the tab order. You could write a user-defined function to
loop through all the data controls which have their Tab Stop property
set to Yes, and of these, return the Name of the one with the lowest Tab
Index setting.
 
Back
Top