totn Access

MS Access 2003: Set focus on first text box on first tab page and go to next record

This MSAccess tutorial explains how to move the focus to the first tab page for the next record when a user presses the tab key on the last tab page 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 multiple tab pages. When the user is on the last text box on the last tab page and presses the tab key, how can I set the focus to the first text box on the first tab page and go to the next record in the form?

Answer: To do this, 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 ShipCountry field on the Shipping tab, we want to automatically move to the first field on the General tab (ie: the CustomerID field) and then move to the next record in the fom.

Microsoft Access

To do this, open your form in design view and select the Properties for the ShipCountry 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
   CustomerID.SetFocus
   DoCmd.GoToRecord
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 ShipCountry field on the Shipping tab page, it will automatically set the focus to the CustomerID field on the General tab page.

Then it will move to the next record in the form. So if you started on record #1, it will move to record #2 in the form.