To use a
TabStrip ActiveX control to view the Customers and the Suppliers tables, follow these steps:
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click
References on the
Tools menu in the Visual Basic Editor, and make sure that the
Microsoft DAO 3.6 Object Library check box is selected.
- Start Microsoft Access and open the sample database Northwind.mdb.
- In the Database window, click Tables, and then click Suppliers.
- On the Insert menu, click AutoForm to create a form based on the Suppliers table.
- On the File menu, click Save As.
- Save the form as frmSuppliers and close the form.
- Repeat steps 2 through 4 for the Customers table.
- Save the form as frmCustomers, and then close the form.
- In the Database window, click Forms, and then click New to create a blank form in Design view, not based on any table or query.
- On the File menu, click Save As, and then save the form as frmTabStrip.
- On the Insert menu, click ActiveX Control, select Microsoft TabStrip Control, version 6.0, and then set its properties as follows:
Name: ctlTabStrip
Width: 6
Height: 3.5
- Right-click the ctlTabStrip control object, point to TabStrip Object, and then click Properties on the shortcut menu that appears.
- In the TabStrip Control Properties dialog box, click the Tabs tab.
Note that the Index value is 1. - Type Customers in the Caption box.
- Click the Insert Tab button to insert a new tab.
Note that the Index value changes to 2. - Type Suppliers in the Caption box.
- Click OK to close the TabStrip Control Properties dialog box.
Make sure that your form is not maximized. Press F11 to bring the Database window to the foreground. - In the Database window, click Forms, and then drag the frmCustomers form from the Database window to the frmTabStrip form (displayed in the background) to create a subform.
- To ensure that the tabs on the ctlTabStrip control are not covered by the subform, set the subform's properties as follows:
Top: .3
Width: 6
Height: 3
Left: 0
- Select and then delete the subform's label.
- Right-click the ctlTabStrip control object, and then click Build Event. Type the following event procedure:
Private Sub ctlTabStrip_Click()
On Error GoTo errhandler
Dim rs As DAO.Recordset, mybookmark As String, I As Integer
Select Case Me!ctlTabStrip.SelectedItem.INDEX
Case 1 ' Show Customers form.
Customers.SourceObject = "frmCustomers"
Case 2 ' Show Suppliers form.
Customers.SourceObject = "frmSuppliers"
End Select
Exit Sub
errhandler:
MsgBox "There is an error"
Customers.SourceObject = "frmCustomers"
End Sub
- On the Debug menu, click Compile Northwind. If there are no compile errors, press CTRL+Q to return to Microsoft Access, and then save the form.
- On the View menu, click Form View.
- Click the Customers tab to display the frmCustomers form. Click the Suppliers tab to display the frmSuppliers form.