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
LVL 6
Mach1proAsked:
Who is Participating?
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.

 
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

Experts Exchange Solution brought to you by ConnectWise

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