totn Access

MS Access 2003: Establish tab order between objects in tab control pages

This MSAccess tutorial explains how to set up the tab order between objects in tab control pages in Access 2003 (with screenshots and step-by-step instructions).

Question: In Microsoft Access 2003/XP/2000/97, I have a form with a main tab box (created with a tab control) with four tabs on it and each tab has a number of text boxes on it. I have indexed these tabs so when the user tabs across, it goes from one tab page to another. However when it reaches the last text box on a particular tab instead of going to the next tab, it goes to the next record.

How can I set up the tab control so that when I tab from the last text box on one tab page, it goes to the first text box on the next tab page?

Answer: To set the tab order between tab pages, you'll need to intervene with VBA code. We'll demonstrate how to do this with an example.

Below we have a form that has a tab control object with 2 tab pages - General and Shipping.

Microsoft Access

When we tab from the ShippedDate field on the General tab, we want to automatically move to the first field on the Shipping tab (ie: the ShipName field).

Microsoft Access

To do this, open your form in design view and select the Properties for the ShippedDate text box. Click on the property called "On Key Down". A button with 3 dots should appear to the right of this property. Click on this button.

Microsoft Access

When the Choose Builder window appears, highlight Code Builder. Click on the OK button.

Microsoft Access

This should bring up the Visual Basic editor:

Microsoft Access

Enter the following code:

If KeyCode = 9 Then
   ShipName.SetFocus
End If

This code will check if the tab key (KeyCode =9) has been pressed. If the user types the tab key while being on the ShippedDate field on the General tab page, it will automatically set the focus to the ShipName field on the Shipping tab page. This will in essence, simulate a tab order between tab pages.

You can place similar VBA code on the last field on each of your tab pages to move the user to the first field on the next tab page.