TabIndex Property

See Also4GRC9X2              ExampleHLT1CV>Low

Applies To

Check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, frame1KX6ZP8, grid2VGT0PT, horizontal scroll bar1JSJOS7, label3MNIZ8D, list boxG11UCK, option buttonJYBO08, picture box31MYIWX, text boxYPYZDG, vertical scroll bar1JSJOS7.

Description

Determines the tab order of a control within its parent form.

Usage

[form.]control.TabIndex[ = index ]

Setting

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.

Remarks

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

 

Note   A control's tab order does not affect its associated access key3XSY0O6.  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.

 

Data Type

IntegerDOKXHY


See Also

Help:

Specifying Access KeysIFK11S

TabStop Property81MAWZ

ZOrder Method1YQ29TM

 

Programmer's Guide:

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

         Else

            X = X + 1                          ' Increment X.

         End If

      Next I

End Sub