Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

Set Next Focus

How is it possible to set the focus to the next control in the tabindex list, without using Sendkeys "{TAB}" or other ugly patches?
0
Mustadio
Asked:
Mustadio
  • 2
1 Solution
 
wileecoyCommented:
It depends on the control, but in most cases you can use .SetFocus.

For example.  With Text1 as a textbox  -

Text1.SetFocus

Will set the focus to your textbox.

If this doesn't work, please include more specific information.

Thanks.
0
 
TheMaskCommented:
I tried this it worked perfect

Private Sub SetFocusToNextControl()

Dim CurrentControl As Control, NextControl As Control

'Get currently focused control
Set CurrentControl = Me.ActiveControl


If CurrentControl.TabIndex = Me.Controls.Count Then
    'If the Last control is the active one
    'set the next one to be any other one
    Set NextControl = Me.Controls(4)
Else
    'This portion sets the nextControl to
    'the next control in the tab list
    For i = 0 To Me.Controls.Count - 1
        Set NextControl = Me.Controls.Item(i)
        If NextControl.TabIndex = CurrentControl.TabIndex + 1 Then Exit For
    Next
End If

'Finally setting the focus
NextControl.SetFocus

End Sub

Enjoy :))
0
 
MustadioAuthor Commented:
Hmmm... I was asking for a command which would have done the thing, since it was actually the way I was doing it myself.  It was what I was calling "patch"...
So, must I conclude there is no true way to do it, instead of making a loop and trying everything?
I guess I would accept your answer anyway...
0
 
TheMaskCommented:
Mustadio, yeah i think i got what do u mean, you was looking for a built in function.
You know i didn't look if this functionality is available as an API call,anyway i will look and i well tell you if i found something
0

Featured Post

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.

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