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?
 
Guy Hengel [angelIII / a3]Connect With a Mentor 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
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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 ArchitectCommented:
Sorry ... ok ... Tab Index Number ... I was thinking Tab control.

mx
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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 ArchitectCommented:
angelIII:

What is

 Dim o As Object
...

  Set o = c  

?

It works with out that

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.