You can use the TabStrip control to conserve screen real estate by displaying data on different "pages" of the same form. The TabStrip control is the same control you're used to seeing in applications such as Microsoft Word and Microsoft Excel. It's easy to implement this control in your own forms. Figure 21.21 shows a form called frmTabbed that uses the TabStrip control.
As the user clicks on each tab, the appropriate information displays. For example, if the user selects a customer on the Customers tab, and then clicks the Orders tab, all orders for the selected customer are displayed. If the user selects an order on the Orders tab, and then clicks the Order Details tab, all details about the selected order are displayed. The code looks like this:
Private Sub tabSelect_Click() 'Evaluate which tab is selected 'Hide and show the appropriate subforms, 'based on which tab is selected Select Case Me!tabSelect.SelectedItem.INDEX Case 1 Me!fsubCustomers.Visible = True Me!fsubOrders.Visible = False Me!fsubOrderDetails.Visible = False Case 2 Me!fsubOrders.Form.RecordSource = _ "Select * from tblOrders Where CustomerID = '" _ & Me!fsubCustomers.Form!CustomerID & "';" Me!fsubCustomers.Visible = False Me!fsubOrders.Visible = True Me!fsubOrderDetails.Visible = False Case 3 Me!fsubOrders.Form.RecordSource = _ "Select * from tblOrderDetails Where OrderID = " _ & Me!fsubOrders.Form!OrderID & ";" Me!fsubCustomers.Visible = False Me!fsubOrders.Visible = False Me!fsubOrderDetails.Visible = True End Select End Sub
Here's how the code works : After adding a TabStrip control to a form, you can double-click it to view its properties (see Figure 21.22). The TabStrip Control Properties dialog box allows you to set properties for the TabStrip control as a whole, as well as for each tab. When the tabs have been added, you can code the TabStrip control's Click event to determine what will happen when the user clicks on each tab.
NOTE
A Tab control is included as a standard control in the Access toolbox, so you don't need to use the ActiveX TabStrip control in your applications. Third-party vendors have Tab controls with more features than Microsoft's. These are all ActiveX-type controls.
Like the StatusBar control, the TabStrip control is one-based. A Case statement evaluates which tab was selected. The frmTabbed form has three subforms: fsubCustomers, fsubOrders, and fsubOrderDetails. When the frmTabbed form is first displayed, only the fsubCustomers subform control is visible. As the user clicks on each tab in the TabStrip control, the appropriate subform is displayed, and the other two subforms are hidden. The RecordSource for fsubOrders is modified at runtime to show only orders for the selected customer from fsubCustomers. The RecordSource for fsubOrderDetails is modified at runtime to show only the order detail items for the order selected on fsubOrders.