Search The Web

Today's Headlines

Monday, June 14, 2010

Microsoft Access Tips & Tricks: Set Tab Indexes Quickly And Correctly

A well-designed form always has a logical order in which the information is entered. Users should be able to enter the information in a logical order simply by tabbing through the form from one field to another rather than having a hard time understanding where their mouse cursor is, and having to adjust information on the fly as they enter it into the form.

If you are interested, you can find my earlier posts on finding the median, the mode, the geometric and harmonic means, ranking every row in a query, selecting random rows out of a table, calculating running sums and averages, calculating running differences, creating histograms, calculating probability masses out of given data, calculating cumulative distributions out of given data, finding percentile scores, percentile values, calculating distinct counts, full outer joins, parameter queries, crosstab queries, working with system objects, listing table fields, finding unmatched rows, calculating statistics with grouping, job-candidate matching, job-candidate matching with skill levels, great circle distances, great circle initial headings, using Excel functions in Access, using the windows file-picker, and using the Access date-picker.

Badly designed forms can be aggravating to users because of the mouse cursor jumping from one control to another with seemingly no pattern to the movement. Just imagine a form in which the cursor starts at last name, jumps to city, then back to first name, area code of phone number, street address, then the rest of the phone number and so on. I am sure you have encountered such forms on websites and silently cursed the designers of the form for not having basic common sense to prevent this from happening.

It is quite easy to prevent this from happening on Microsoft Access forms though. All form controls have a couple of properties that make it easy to control how focus moves among the different controls as a user tabs through them. This is called the tab order of the form, and is a very important element of designing user-friendly forms.
Tab Index
The first of these properties is the Tab Stop property. This is a "yes or no" property which controls whether this control ever gets the focus when users tab from control to control on a form. Setting this property to No will ensure that users never tab into this control. For instance, this could be the case for controls that hold search results on a form, for instance. Users can mouse into such a control if they need to copy the contents of the control for some reason, but if no user input is needed in a control, it is best to set its Tab Stop property to No, so that users don't have to waste time tabbing into and then out of such a control.

The next property, which will be the main focus of this post, is the Tab Index property. The Tab Index of a control determines the order in which the control gets the focus when the user tabs from control to control on the form. Thus, this property controls the overall usability of the form when it comes to efficient data entry by the users.

The focus on a form always starts on the control with the lowest Tab Index property. The valid values for this property are 0 through the number of controls on the form - 1. The problem with this property is that as controls are added to the form, regardless of where they are added on the form, their Tab indices are initially set so that the focus moves from earliest added control to latest added control. This, in most cases, unless you designed your form on paper and never changed your mind or made a mistake, is usually not the tab order you actually want.

I always make it a point to adjust the Tab Index properties of all my controls as the last step in a form's design. That way, I know precisely the controls on the form, and I know for sure what order it makes sense to enter the information in. If you adjust the Tab Indexes in the middle of form design, then as your design changes, the tab order will probably become illogical, undoing all your hard work.

Assuming your form is now fully designed and you are ready to assign the Tab Index properties, what is the best way to go about it. You can open up the properties of each control in the order in which you want the focus to move and assign them successively higher numbers, starting from 0. But I find this method somewhat painful and error-prone. You have to keep track of the control number you are on, and keep remembering the number just below that control number (the first control gets Tab Index 0, control number two gets Tab Index 1, and so on). Instead, here is an easier way to do this.

Start with the last control and work backwards. Open up the property sheet of the last control and assign it Tab Index 0. Then click on the control you want to have focus just before that, and again assign it Tab Index 0. Internally, Access is very smart. When you assigned the second control the same Tab Index as the first control, it automatically assigns the second control the Tab Index you entered and increments all other Tab Indexes by 1 to account for the fact that there is now a new "first" control. So, the last control now gets a Tab Index of 1.

Work backwards like this, each time assigning Tab Index of 0 to each control in backwards order. Eventually, this will result in the first control (which you will assign a Tab Index of 0 at the very end) retaining a Tab Index of 0, while other controls have their Tab Indexes incremented step by step until the last control gets a Tab Index of number of controls with tab stops on them - 1. This method is easier to implement because you don't have to keep track of what Tab Indexes you have assigned already and what you are supposed to assign at each step. You just have to work backwards and always assign a Tab Index of 0 to every control. That is all there is to it.
Input Mask
Another trick I sometimes find useful is to use the Autotab property of controls. This is useful for controls in which the entry is in a fixed format. This will work for phone numbers, dates, and other information that has a fixed format and length. To use the Autotab property, you have to set an input mask for the control, then turn the Autotab property on. When both properties are satisfied, when the user enters input that satisfies the input mask, the focus automatically moves to the next control on the form. The user does not have to tab out of the control at all.

Thus, I sometimes put two controls right next to each other and designate the combination of both controls as the phone number. But one of them is actually the area code and the other is the actual phone number. As soon as the user enters three digits (which is the length of the input mask for the area code control), the cursor moves to the phone number control. When the user enters 7 more digits, the cursor then moves automatically to the next control on the form.

Search in Access Help for more information on how to enter input masks for form controls. Remember, the input mask has to be set, AND the Autotab property has to be turned on for this to work on the form.

Hope this post has been helpful in solving any problems you might have had with setting or using the Tab Index in Access. Hopefully it also answered any questions you might have had about the Autotab property of controls on a form. If you have any problems or concerns, please feel free to let me know by posting a comment. If you have other questions on Access that you would like me to address in future posts, please feel free to let me know through your comments too. Good luck!

Visitors Country Map

Free counters!

Content From

In the News

Article of the Day

This Day in History

Today's Birthday

Quote of the Day

Word of the Day

Match Up
Match each word in the left column with its synonym on the right. When finished, click Answer to see the results. Good luck!



Spelling Bee
difficulty level:
score: -
please wait...
spell the word:

Search The Web