See Also Example
Check box, combo box, command button , directory list box , drive list box , file list box , frame , grid , horizontal scroll bar , label , list box , option button , picture box , text box , vertical scroll bar .
Determines the tab order of a control within its parent form.
[form.]control.TabIndex[ = index ]
The valid range is any integer from 0 to (n-1), where n is the number of controls on the form that have a TabIndex property. Assigning a TabIndex value of less than 0 generates an error.
By default, Visual Basic assigns a tab order to controls as you draw them on a form. Each new control is placed last in the tab order. If you change the value of a control's TabIndex property to adjust the default tab order, Visual Basic automatically renumbers the TabIndex of other controls to reflect insertions and deletions. You can make changes at design time using the Properties window or at run time in code.
All controls except menus and timers are included in the tab order. At run time, invisible or disabled controls and controls that cannot receive the focus (frames and labels) remain in the tab order but are skipped during tabbing.
The TabIndex property is not affected by the ZOrder method.
Note A control's tab order does not affect its associated access key . If you press the access key for a frame or label, the focus moves to the next control in the Tab order that can receive the focus.
When loading forms saved as ASCII text, controls with a TabIndex property that aren't listed in the form description are automatically assigned a TabIndex value. In subsequently loaded controls, if existing TabIndex values conflict with earlier assigned values, the controls are automatically assigned new values.
Specifying Access Keys
Chapter 3, "Creating and Using Controls"
TabIndex Property Example
The example reverses the tab order of a group of buttons by changing the TabIndex property on a command button array To try this example, paste the code into the Declarations section of a form that contains four command buttons. Set the Name property to CommandX for each button to create the control array . Then press F5 and click the form to reverse the tab order of the buttons..
Sub Form_Click ()
Dim I, X ' Declare variables.
' Reverse tab order by setting start value of X.
If CommandX(0).TabIndex = 0 Then X = 4 Else X = 1
For I = 0 To 3
CommandX(I).Caption = X ' Set caption.
CommandX(I).TabIndex = X - 1 ' Set tab order.
If CommandX(0).TabIndex = 3 Then
X = X - 1 ' Decrement X.
X = X + 1 ' Increment X.