MS Access 2003: Change the tab order on a form with VBA code
This MSAccess tutorial explains how to change the tab order of the controls on a form using VBA code in Access 2003 (with screenshots and step-by-step instructions).
Question: In Microsoft Access 2003/XP/2000/97, I want to be able to change the tab order on a form using VBA code. How can I do this?
Answer: We've created a sample Access database that you can download that demonstrates how to change the tab order on a form.
Download version in Access 2000
Let's look at the example. Below, we have a form where the user can change the tab order by selecting a radio button.
If the user selects the "Order tabs down and then across" radio button, the tab order will be as follows: Supplier ID, Company Name, Contact Name, Contact Title, Phone, Fax, and Home Page.
If the user selects the "Order tabs across and then down" radio button, the tab order will be as follows: Supplier ID, Phone, Company Name, Fax, Contact Name, Home Page, and Contact Title.
This tab reordering is done by the following code:
Private Sub frameTabOrder_Click() 'Order tabs down and then across was chosen If frameTabOrder.Value = 1 Then [SupplierID].TabIndex = 0 [CompanyName].TabIndex = 1 [ContactName].TabIndex = 2 [ContactTitle].TabIndex = 3 [Phone].TabIndex = 4 [Fax].TabIndex = 5 [HomePage].TabIndex = 6 'Order tabs across and then down was chosen Else [SupplierID].TabIndex = 0 [Phone].TabIndex = 1 [CompanyName].TabIndex = 2 [Fax].TabIndex = 3 [ContactName].TabIndex = 4 [HomePage].TabIndex = 5 [ContactTitle].TabIndex = 6 End If End Sub
Advertisements