TabIndex

Returns or sets the tab order of most objects within their parent form.

Syntax

object.TabIndex [= index]

The parts of the TabIndex property syntax are described in the following table.

Part Description
object An object expression that evaluates to an object.
index An 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, with the exception of the Menu, Timer, Line and Shape controls, which are not included in the tab order. At run time, invisible or disabled controls and controls that cannot receive the focus (Frame and Label controls) remain in the tab order but are skipped during tabbing.

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.

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 control, 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 are not 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.

When you delete one or more controls, you can use the Undo command to restore the controls and all their properties except for the TabIndex property, which cannot be restored. TabIndex is reset to the end of the tab order when you use Undo.