Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Focus to the Next Item in the Tab Sequence 2

Status
Not open for further replies.

spongie1

Technical User
Nov 24, 2003
57
US
Sometimes when you at the early stages of the learning process, you don't have the vocabulary necessary to formulate an intelligible question.

I have a form with comboboxes and subform-pivot charts. Changes made to the comboboxes are reflected in the pivot charts... kind of a poor man's data analysis tool.

The way that I am updating my charts is by using requery statements. One statement for every chart.

I have been triggering the updates OnChange in each combobox.

The net effect is that you select from the combobox and then you tab to the next combobox.

This works fine for comboboxes, but for textboxes... I am having more problems.

I set a flag true in the OnChange event. If the flag is set, I perform requeries to update the charts in the OnLostFocus event for the textbox.

However, I do not know how to set focus to the next combobox, so the net effect is that I have to hit tab twice to go to the next box.

How do I set focus to the next item in the tab sequence in vba?


are just learning, you don't
 
In the OnExit of the text box use Me.NextComboBoxName.SetFocus
 
Use the .SetFocus parameter. If your next item is named Combo21, then use:

Me.Combo21.SetFocus

HTH

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Place the code below in the after update event of the field prior to the field you want to go to

YourNextFieldName.SetFocus

Dont forget to change the name to your Field/Cbo

Hope this helps
Hymn
 
I truly appreciate the responses. However, I may have asked the question improperly the first time.

What I really want to know is... If you are at item #3 in the tab sequence, how do you set focus to item #4 if you do not have the name of item 4?

I want to move to the next item based solely on the order they follow in the tab sequence.

Something akin to SetFocus TabIndex 7.
 
In the design mode of the form you can assign the tab order. If you didn't design the form you can get the item names from there also. Just right click on the item (text box, etc) and select properties. There you can get the item's name.
 
This is still not what I want. I want to reference a listbox or combobox by its tab index. Is this possible other than writing a loop to move through all controls finding the one with next highest tab number?

This would allow me to setFocus to the item with the next greatest tab index.
 
The only way to go about it really would be to cycle through all the control on the page, check the tab indexes against the one of the control that you currently have highlighted.
 
Spongie1,

this may be what you want. You may call the function from the AfterUpdate event of a control.

Function fSelectNextControl()
'Purpose: Set focus to the next control in the form's tabIndex.

Dim rctlNew As Control
Dim iTab As Integer
Dim rctlOld As Control
Dim iNewTab As Integer

Set rctlOld = Screen.ActiveControl
iNewTab = rctlOld.TabIndex + 1

For Each rctlNew In Me.Controls
iTab = rctlNew.TabIndex
If Not Err And (iTab = iNewTab) Then
With rctlNew
'Set properties of the control, e.g.
.Enabled = True
.Locked = False
.SetFocus
Select Case .ControlType
Case acTextBox: 'Do something
Case acListBox: 'Do Something
Case acComboBox: 'Do Something
Case acOptionGroup:'Do Something
Case Else: 'Do Something
End Select
Exit For
End With
End If
Next

Set rctlOld = Nothing
Set rctlNew = Nothing

End Function

I have extracted the code from a larger module I use - it is not tested in this form.

Hope this helps, georgp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top