Accommodating keyboard users

Many users prefer to navigate through a dialog box by using the keyboard: The Tab and Shift+Tab keystrokes cycle through the controls, and pressing a hot key (an underlined letter) operates the control. To make sure that your dialog box works properly for keyboard users, you must be mindful of two issues: tab order and accelerator keys.

CHANGING THE TAB ORDER OF CONTROLS

The tab order determines the sequence in which the controls are activated when the user presses Tab or Shift+Tab. It also determines which control has the initial focus. If a user is entering text into a TextBox control, for example, the TextBox has the focus. If the user clicks an OptionButton, the OptionButton has the focus. The control that's first in the tab order has the focus when a dialog box is first displayed.

To set the tab order of your controls, choose View Tab Order. You can also right-click the UserForm and choose Tab Order from the shortcut menu. In either case, Excel displays the Tab Order dialog box, as shown in Figure 13-8. The Tab Order dialog box lists all the controls, the sequence of which corresponds to the order in which controls pass the focus between each other in the UserForm. To move a control, select it and click the arrow keys up or down. You can choose more than one control (click while pressing Shift or Ctrl) and move them all at once.

T.LftJ_

zju u

Figure 13-8: Use the Tab Order dialog box to specify the tab order of the controls.

Alternatively, you can set an individual control's position in the tab order via the Properties window. The first control in the tab order has a TabIndex property of 0. Changing the TabIndex property for a control may also affect the TabIndex property of other controls. These adjustments are made automatically to ensure that no control has a TabIndex greater than the number of controls. If you want to remove a control from the tab order, set its TabStop property to False.

Note Some controls, such as Frame and MultiPage, act as containers for other controls. The controls inside a container have their own tab order. To set the tab order for a group of OptionButtons inside a Frame control, select the Frame control before you choose the View

Tab Order command.

SETTING HOT KEYS

You can assign an accelerator key, or hot key, to most dialog box controls. This allows the user to access the control by pressing Alt+ the hot key. Use the Accelerator property in the Properties window for this purpose.

Tip Some controls, such as a TextBox, don't have an Accelerator property because they don't display a caption. You still can allow direct keyboard access to these controls by using a Label control. Assign an accelerator key to the Label and put it ahead of the TextBox in the tab order.

Testing a UserForm

You'll usually want to test your UserForm while you're developing it. There are three ways that you can test a UserForm without actually calling it from a VBA procedure:

Run Sub/UserForm command.

■ Click the Run Sub/UserForm button on the Standard toolbar.

These three techniques all trigger the UserForm's Initialize event. When a dialog box is displayed in this test mode, you can try out the tab order and the accelerator keys._

4 PREV

NEXT

0 0

Post a comment