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

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
 
S

Steve Schapel

Alan,

On the Exit event of the last control of the subform, put code like this...
Me.Parent.Controls(0).SetFocus
 
M

Malcolm Cook

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."
 
A

ambradnum

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.
 
S

Steve Schapel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top