• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

How to go to a specific TabIndexed control

I know the name of the control in a form  and can retrieve the tabIndex.  eg.  i = Controls("name of control").TabIndex
How can I set the focus to a specific control using the tabindex? For example I want to set focus to  i + 3
0
Mach1pro
Asked:
Mach1pro
1 Solution
 
tbsgadiCommented:
Hi Mach1pro,
How about Controls(i+3).setfocus

Good Luck!

Gary
0
 
Mach1proAuthor Commented:
tbsgadi
Your code would set the focus to the next control in the control indexes, not the next tabIndex.
0
 
flavoCommented:
Hi Mach1pro,
This is the only way I can think of:

    Dim i As Long
    Dim c As Control
    i = Me.myControl.TabIndex

    For Each c In Me.Controls
        On Error Resume Next
        If c.TabIndex = i + 3 Then
            c.SetFocus
        End If
    Next

Dave :-)
0
 
Leigh PurvisDatabase DeveloperCommented:
You might want to check for TabStop being set to true also and count on only if that is met.

That would involve iterating through the controls at least three times!

But if you're sure it won't be then yep - Dave's way is the way.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now