SetFocus Using Tab Index...

A text box has tab index of 4.

Question: How can I send focus to this text box using its tab index number?

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You s/b able just to directly set it - unless the text box is on a subform ?

Me.txtTextBoxOnTabPage.SetFocus

What is the problem ?

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Sorry ... ok ... Tab Index Number ... I was thinking Tab control.

mx
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please create the below vba macro.
all you have then to do is to call it with the form and the tabindex as parameter

Public Sub SetFocusOnTabIndex(f as Form, tabIndex as int)
  Dim c As Control
  Dim o As Object
  
  For Each c In f.Controls
    Set o = c
    On Error GoTo Err
    If c.TabIndex = tabIndex  Then
      c.SetFocus
      Exit Sub
    End If
next_control:
  Next
  
Exit Sub
Err:
  Resume next_control
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
I think

tabIndex as int

needs to be

tabIndex as integer

or it won't compile.

mx
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
@DatabaseMx: you are correct.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
angelIII:

What is

 Dim o As Object
...

  Set o = c  

?

It works with out that

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.