Solved

Set Next Focus

Posted on 2000-03-28
4
384 Views
Last Modified: 2008-02-01
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
Comment
Question by:Mustadio
  • 2
4 Comments
 
LVL 4

Expert Comment

by:wileecoy
ID: 2665985
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
 

Accepted Solution

by:
TheMask earned 50 total points
ID: 2665987
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
 

Author Comment

by:Mustadio
ID: 2685815
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
 

Expert Comment

by:TheMask
ID: 2686438
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now