Page 304 - Excel Progamming Weekend Crash Course
P. 304

r540629 ch21.qxd  9/2/03  9:35 AM  Page 279




                  Session 21 — Advanced User Form Techniques                             279

                  When a control has the focus, it receives user input as dictated by the nature of the
               control. For example
                   A TextBox with the focus accepts characters and editing commands from the
                   keyboard.
                   A CheckBox or OptionButton with the focus is toggled between True and False by
                   the Spacebar.
                   A CommandButton with the focus is selected.
                   The items in a ComboBox or ListBox with the focus can be scrolled through using
                   the Up and Down arrow keys.
                  When the form is displayed, the user can move the focus to a control by clicking it
               (clicking also selects CommandButton controls). The user can also move the focus by pressing
               Tab or Shift+Tab. The order in which the focus moves between controls is called the tab
               order, with Tab moving forward in the order and Shift+Tab moving backwards.

                          If you want clicking to select a CommandButton control without moving the
                          focus to it, set the control’s TakeFocusOnClick property to False. This is
                   Tip    useful when you want a CommandButton to carry out some action, but leave
                          the form displayed while leaving the focus unchanged.
                  For some forms, having the correct tab order can make a difference in how usable the
               form is. In a data entry form, for example, the tab order should follow the natural order of
               data entry, with the last tab taking the focus to the OK button. There are two control prop-
               erties that relate to the tab order:
                   TabStop. If True, the control can receive the focus by tabbing. If False, the control
                   can receive the focus only by clicking with the mouse. The default is True for all
                   controls.
                   TabIndex. A numeric value specifying the position of the control within the tab
                   order. The first control has TabIndex equal to zero.

                  When you place controls on a form, the TabIndex property is assigned in order. Often
               this does not result in the tab order that is suitable for the form. There are three ways to
               change the tab order. You can manually edit the TabIndex property of all the controls on
               the form, but this is time-consuming. You can also use the View ➪ Tab Order command,
               which displays the Tab Order dialog box as shown in Figure 21-6. To change the tab order,
               select a control in the list and use the Move Up and Move Down buttons to change its
               position in the tab order.
                  The last way to change the tab order is in code, by calling the UserForm object’s
               SetDefaultTabOrder method. This method creates a tab order beginning with the control
               in the top left corner of the form and then moving across and down. You can also call this
               method on a Frame control to set the tab order for controls on the frame. This method of
               setting the tab order is appropriate only when the controls on the form are arranged accord-
               ing to the desired tab order.
   299   300   301   302   303   304   305   306   307   308   309