Previous Page
Next Page

Hack 26. Be Tab-Smart

Override a form's tab order so that users get to the entry boxes they need.

Setting the tab order is probably not the biggest thing on your mind when you design a form. It doesn't really require much planning or analysis.

Typically, you do it at the end, after all the controls are in place. To be honest, at times I've simply forgotten to set a tab order on my forms. But, of course, the user community lets me know when that happens.

So, I started thinking that if tab stops on a form are really important to users, why not go one step better and make the tab order work more intelligently. On some forms only some boxes receive entries. A smart way to tab through a form in this situation is to sense which entry boxes can be skipped.

This makes sense when the condition or entry into a text box is based on some understandable logic flow. For example, if you're entering information about a new customer, usually you fill in every field. However, when you're entering a piece of information on an existing customer, most likely you tab over several text boxes.

Figure 3-24 shows a form in which a selection has been made from a combo box. The combo box, named Status, has four choices: Enrolled, Walk-In, Phone, and Renewal.

In the Exit event of the combo box, a Select Case statement sets the focus to different form controls, depending on the selection made in the combo box. For example, a status of Walk-In is used for unregistered people who come in without an appointment. They need to be set up in the system, so the next entry box to go to is the Referral Source. By contrast, when an Enrolled person comes in, the next box to enter is Comments. Here is the code in the Exit event:

       Private Sub status_Exit(Cancel As Integer)
       Select Case status
         Case "Enrolled"
            Me.txtComments.SetFocus
         Case "Walk-In"
            Me.txtReferralSource.SetFocus
         Case "Renewal"
            Me.txtStudentFirstName.SetFocus
       End Select
       End Sub

The gist of this approach is that you can apply rules to the tab order based on what makes sense to the business. As another example, a database system at a car dealership should skip right over a section about what type of new car a customer wants to purchase if she is in the market for a used car. If the section about new cars contains 12 fields, the salesperson needs to tab through 12 unneeded boxes, unless a better method is in place. Instead, some other control on the form can act as a flag so that you can implement smart tabbing. Using the Exit events of controls is a great way to support this business workflow.

Figure 3-24. A combo box selection to drive the tab order


    Previous Page
    Next Page