Working with the Tab Control

As you have just seen, a subform is an excellent way to create a form that lets you edit information from the one side of a relationship in the main form (contacts) while editing or viewing data from the many side of a relationship (contact events or contact products) in the subform window. Building a subform is very simple for a single one-to-many relationship. But what can you do when you have either multiple relationships or lots of data you need to deal with on a form, and including all this information makes your form too large to fit on your screen? Access provides a tab control that lets you place multiple controls on individual tabs within a form. The controls on a tab can be as complex as subforms (in the case of the Conrad Systems Contacts database, to display related companies, events, and products) or as simple as text boxes (which can display the potentially lengthy information in the Notes field). You can see the frmContactsPlain form (the simple copy of the form that doesn’t have all the advanced features of the production form) with the tab that shows contact events selected in Figure 15-35. You can select the other available tabs to see the detail information for the contact—the companies associated with the contacts (in a subform on that tab)—and the products the contact has purchased (in another subform).

The tab control allows you to place multiple subforms and controls on a tab page, such as this tab, to edit contact events.

Figure 15-35. The tab control allows you to place multiple subforms and controls on a tab page, such as this tab, to edit contact events.

Working with the tab control is quite simple. If you like, you can start with a simple columnar form built by the Form Wizard. Use qxmplContactsSorted as the record source, and include the ContactType, Title, LastName, FirstName, MiddleInit, and Suffix fields. Switch to Design view, and create some space at the bottom of the form to add your tab control. You can also start with frmXmplContacts1, which you can find in the ContactsDataCopy.accdb sample database. To build a control that lets you alternately see company, contact event, or liner notes information for the current contact, perform the following steps:

  1. On the Design tab, in the Controls group, click Tab Control, and drag an area on the form starting on the left side just under the Suffix combo box control and approximately 6.25 inches wide and 2 inches high. Access shows you a basic tab control with two tabs defined. Open the Property Sheet window, and set the Tab Fixed Width property to 1“ so that all the tabs will be the same size and wide enough to add captions later.

  2. While the tab control has the focus, click the Insert Page button in the Controls group on the Design tab, as shown here. Access will add a third tab to the control.

    The tab control allows you to place multiple subforms and controls on a tab page, such as this tab, to edit contact events.
  3. Access always inserts new tabs at the end of the tab sequence. If you want to place the new tab in the middle of the tab order, you can select the tab and set its Page Index property. The Page Index of the first tab is 0, the second is 1, and so on. Another way to set the tab sequence is to right-click the control and then click Page Order to see the dialog box shown next. Select a tab, and move it up or down to get the sequence you want.

    The tab control allows you to place multiple subforms and controls on a tab page, such as this tab, to edit contact events.
  4. Click the first tab, open the Property Sheet window (if it’s not already open), and set the Caption property to Companies.

  5. Click the second tab, and set the Caption property to Events.

  6. Click the third tab, and set the Caption property to Notes.

  7. Click the Companies tab to bring it to the front. Click the Subform/Subreport button in the Controls group, and set the Auto Label property in the Property Sheet window to No. Add a subform control to the Companies tab, set its Source Object property to fsubXmplContactCompanies (the sample database contains built-in subforms to make this exercise easy), and set the Link Child Fields and Link Master Fields properties to ContactID. You can also drag the subform from the Navigation pane and place it on the tab if you like.

  8. Click the Events tab, and add the fsubXmplContactEvents form to that tab as a subform. Be sure to set the link properties of the subform control to ContactID.

  9. Click the Notes tab to bring it to the front. Open the field list, drag the Notes field onto this tab, and remove the attached label. Expand the Notes text box control to almost fill the tab.

  10. Adjust the positioning and size of the controls on each tab. Place each control very near the upper-left corner of each tab. The actual Top and Left settings will vary depending on where you placed the tab control. (These settings are relative to the Detail section of the form, not the tab control.) You can place one where you want it and then copy the Top and Left settings to the other two controls so that they exactly line up. It’s important you do this so that the controls don’t appear to jump around on the tab control as you move from tab to tab. Select each control, and then click the To Fit button under the Size/Space command in the Sizing & Ordering group on the Arrange tab.

Save the changes to your form as frmContacts4. Your result up to this point should look something like Figure 15-36. You can find this form saved as frmXmplContacts4 in the sample database. Note that clicking each tab in Design view reveals the controls you stored on that tab.

Your tab control in Design view shows three tabs with various controls.

Figure 15-36. Your tab control in Design view shows three tabs with various controls.

Access 2010 includes several new formatting features you can use to customize the look and feel of your tab control. Select the tab control and then click the Change Shape button in the Control Formatting group on the Format tab. Access displays a gallery of eight shape styles you can use to change the shape of your tabs, as shown in Figure 15-37. The default shape for tabs is Rectangle, but let’s select a different tab style for our form. Click the shape called Round Same Side Corner Rectangle to give your tabs a more rounded edge instead of the default sharp edges.

You can choose from a gallery of eight shape styles for tabs.

Figure 15-37. You can choose from a gallery of eight shape styles for tabs.

Now that you’ve applied a new shape style, Access changes the Use Theme property of the tab control to Yes because you are using one of the new theme styles in Access 2010. You cannot see the caption on the first tab because Access changes the Hover Fore Color and Pressed Fore Color properties to white, which blends in with the background. Open the Property Sheet window, select the tab control, and change these two properties so we can see the caption clearly. On the Hover Fore Color property, select the Dark Blue standard color option (you can enter #2F3699 directly into the property if you want). The Hover Fore Color property lists the color used for the tab captions when you hover over the tab. Move down to the Pressed Fore Color property and select the Black standard color from the color picker. The Pressed Fore Color property lists the color used for the tab captions when you click a tab.

You can further customize the tab control by providing some color and gradients to the tabs. Select the tab control, click the Shape Fill command in the Control Formatting group on the Arrange tab, and then click Dark Blue 2 in the Standard Colors section of the color picker to fill the tabs with a blue color. Click the Shape Fill command again and then click Gradient. Access displays a gallery of 13 gradient variations, as shown in Figure 15-38. The default option, No Gradient, tells Access not to use any fill color gradients for the control. Click the Linear Right gradient variation to show a transition of darker to lighter color from right to left of the blue fill color you chose earlier.

You can select different gradient variations to use with the fill color of the tabs on tab controls.

Figure 15-38. You can select different gradient variations to use with the fill color of the tabs on tab controls.

Save the changes to your form as frmContacts5. Switch to Form view to see the results of your changes, as shown in Figure 15-39. Click the tabs for the tab control and observe how Access changes the fore color of the captions as you hover over and click the tabs. You can find this form saved as frmXmplContacts5 in the sample database.

Your completed tab control in Form view should now look like this.

Figure 15-39. Your completed tab control in Form view should now look like this.

Table 15-1 lists other useful tab control property settings.

Table 15-1. Useful Tab Control Formatting Properties

Property

Settings

Usage

Multi Row

No (default)

If the control has more tabs than will fit on a single row, the control displays horizontal scroll arrows in the upper-right corner of the tab control to move through all the tabs.

 

Yes

If the control has more tabs than will fit in a single row, the control displays multiple rows of tabs.

Style

Tabs (default)

The control displays tabs to select the various pages.

 

Buttons

The control displays buttons (which look like command buttons but work like the buttons in an option group) to select the various pages.

 

None

The control displays neither tabs nor buttons. Different pages can be displayed from a Visual Basic procedure or a macro by setting relative tab numbers in the tab control’s Value property.

Tab Fixed Height

0 (default)

The tab height is based on the font properties of the tab control or the size of the bitmap you define as a picture to be displayed on the tab.

 

[size in inches]

The tab height is fixed at the value entered.

Tab Fixed Width

0 (default)

The tab width is based on the font properties of the tab control and on the number of characters in the caption or the size of the picture on the tab.

 

[size in inches]

The tab width is fixed at the value entered.

Back Style

Normal (default)

The control’s back style is solid.

 

Transparent

The control’s background is transparent. If you have controls or a background image behind the tab control, those elements can be seen through the tab control.

Use Theme

Yes (default)

The control uses the new control theme styles such as gradients, shape fill, and shape styles.

 

No

The control does not use any new control theme styles. Note that applying a Shape Style, Shape Fill, or Shape Outline to the control changes this property to Yes.

Back Color

[color values]

Sets the background color of the control.

Border Style

Solid (default)

Sets the line style for the outline of the control. You can make the border transparent or specify a border that is a solid line, dashes, short dashes, dots, sparse dots, dash dot, or dash dot dot.

Border Color

[color values]

Sets the border color of the control.

Hover Color

[color values]

Sets the interior color of the tab when you hover the mouse over the tab.

Pressed Color

[color values]

Sets the interior color of the tab when you click the tab.

Hover Fore Color

[color values]

Sets the font color of the tab caption when you hover the mouse over the tab.

Pressed Fore Color

[color values]

Sets the font color of the tab caption when you click the tab.

Fore Color

[color values]

Sets the default font color of the tab captions.

Troubleshooting

Why can’t I see multiple rows of tabs in my tab control?

If you are using a tab control with the Multi Row property set to Yes and the Use Theme property set to Yes, Access does not display the tab pages on multiple rows. To see multiple rows on your tab control, you must set the Multi Row property to Yes and the Use Theme property to No. Note that when you set the Use Theme property to No, you cannot use any of the new theme styles, such as gradients, shape fills, and shape styles, for the tab control.