When you build an Access application to be used by others, it’s generally good practice to display to users only the parts of the database that they need to complete the major tasks in your application. Your main form that users interact with should be an intuitive interface that helps guide your users to the forms and reports they need to use in the database. The Switchboard Manager, included in Access for many releases, helps build a form that allows users to navigate to the various parts of an Access database. While the Switchboard Manager functions, at least on a simple level, to navigate to parts of an application such as opening forms and reports, it lacks the ability to do additional customization. In a large application with many objects, you have to navigate many levels deep into sublevels of the switchboard form to get to different areas. The Switchboard Manager might work for some Access client applications, but when you look at interfaces for websites, the switchboard model is generally not used.
Access 2010 includes a new type of form control, called a navigation control, to help you design a navigational interface similar to websites. Most websites on the Internet display tabbed style navigation buttons along the top or down the left side of the web page. Navigation controls in Access 2010 are designed to mimic this type of web interface. A navigation button works essentially the same as a command button. When you click a navigation button, Access responds to the click event and performs an action. (You’ll learn all about events in Part VI.)
To demonstrate creating and using navigation controls in your Access databases, open the Contacts Navigation sample web database (ContactsNavigation.accdb) found on the companion CD. When the web database opens, Access displays the startup form called Home, as shown in Figure 15-46. The Home form contains a navigation control that allows you to easily view and interact with the forms and reports in the database. Beneath the label title in the form’s Header section, you’ll see four buttons displayed horizontally across the top—Contact List, Datasheet, Address Book, and Phone List. If you click these buttons, Access changes the form or report displayed in the bottom portion of the navigation control. Underneath the Contact List button, you’ll see another set of five buttons—All, A–G, H–M, N–T, and U–Z. If you click these buttons, Access displays the frmContactList form, but filtered to show only contact last names within a range of letters. You’ll notice if you click any other top-level button besides the one labeled Contact List, you don’t see the second level of buttons.
A form with a navigation control is sometimes referred to as a navigation form because you can use the form as your main form to navigate to different parts of your application. You need to remember, though, that a navigation control is not a new form type, it is a control on a form.
Figure 15-46. The navigation control on the Home form allows you to navigate to the forms and reports in the database.
Close the Home form now, and let’s create a new form with a navigation control just like this Home form. In the Forms group on the Create tab, click Navigation. Access displays a drop-down list of six types of navigation controls, as shown in Figure 15-47. Here are the navigation control options in detail:
Horizontal Tabs. Create a navigation control with a single row of navigation buttons horizontally across the top of the control.
Vertical Tabs, Left. Create a navigation control with a single column of navigation buttons down the left side of the control.
Vertical Tabs, Right. Create a navigation control with a single column of navigation buttons down the right side of the control.
Horizontal Tabs, 2 Levels. Create a navigation control with two rows of navigation buttons horizontally across the top of the control. The second level of navigation buttons changes based on the navigation button selected in the top-level row.
Horizontal Tabs And Vertical Tabs, Left. Create a navigation control with a single row of navigation buttons horizontally across the top and a single column of navigation buttons down the left side of the control. The navigation buttons on the left side can change based on the navigation button selected in the top-level row.
Horizontal Tabs And Vertical Tabs, Right. Create a navigation control with a single row of navigation buttons horizontally across the top and a single column of navigation buttons down the right side of the control. The navigation buttons on the right side can change based on the navigation button selected in the top-level row.
Click Horizontal Tabs, 2 Levels from the drop-down list of navigation control options to begin creating your form. Access creates a new blank, unbound form with your navigation control and opens the form in Layout view, as shown in Figure 15-48.
Although we’ll only be showing you an example of using navigation controls on a web form in a web database, you can also create navigation controls on client forms, too. If you are in a client database, you create a new form with a navigation control by clicking the Navigation button in the Forms group on the Create tab. You can also click the Navigation Control button in the Controls group on the Design tab to drop a navigation control onto an existing form.
A navigation control is a unique control in Access because it is actually a collection of controls interlinked together. At the top of the control, Access creates the top-level navigation control—the container for the main level of navigation buttons. Below the top-level navigation control, you’ll see the second-level navigation control—the container for the child level of navigation buttons. Beneath the second-level navigation control, you’ll see a large subform container. (By default, Access makes the subform container a large size, but you can resize the container to a smaller size if you want.) All these controls work together and depend on one another. It might be confusing to see in the Property Sheet window that these controls are all independent controls with their own properties; however, you cannot have a navigation control without a subform container. Access needs the subform container to display forms and reports.
In each of the navigation controls, you’ll see an [Add New] navigation button. The [Add New] navigation button performs a special function to assist you with creating additional new navigation buttons in your navigation controls. You cannot delete the [Add New] navigation button from your navigation control, but Access does not display this button when you open the form in Form view.
The first form we’d like to display in the navigation control is the form called frmContactList. The frmContactList form is a continuous form that lists a few details about each contact in the database. To create a new navigation button that displays the frmContactList form in the subform container, click inside the top-level [Add New] navigation button and then type the name of the form frmContactList, as shown in Figure 15-49.
Figure 15-49. Type a form or report name in the [Add New] navigation button to create a new navigation button.
After you type the form name, press Enter and Access creates a new navigation button to the left of the [Add New] navigation button. Access also now displays the frmContactList form in the subform container, as shown in Figure 15-50.
Open the Property Sheet window and let’s take a look at the properties for a navigation button. A navigation button has properties that most other controls have as well, such as properties for the control name, caption, font size, font style, gridlines, color options, etc. Two properties, however, are unique to navigation buttons—Navigation Target Name and Navigation Where Clause, as shown in Figure 15-51. In the Navigation Target Name property, Access provides a drop-down list of all the form and report names in your database. This property tells Access which form or report to display when you click the navigation button. When you typed the form name into the [Add New] navigation button, Access filled in this property for you. You can use the Navigation Where Clause property to provide an optional WHERE clause to filter the results of the selected form or report in the Navigation Target Name property. (We’ll show you how to do that later in this section.) By default, Access set the Caption property for the navigation button the same as the name of the form. Click in the Caption property, and change the caption to Contact List.
If you are using a web form in a web database, Access filters the drop-down list of form and report names in the Navigation Target Name property to display only web forms and web reports. If you are using a client form, Access displays both web and client forms and reports in your database in the drop-down list for the Navigation Target Name property.
You can continue to add more navigation buttons to the top-level navigation control by typing in the other form and report names in the [Add New] navigation button; however, there is a much easier way to add additional navigation buttons. Close the Property Sheet window, if you still have it open, and make sure you’ve expanded the Navigation pane to see the database objects. Select the frmContactDatasheet from in the Navigation pane and then drag the form to the right of the Contact List navigation button you just created. When you have it positioned just right, Access displays a vertical I-bar to the right of the Contact List navigation button, as shown in Figure 15-52.
Release the mouse and Access creates another navigation button and displays the frmContactDatasheet in the subform container, as shown in Figure 15-53. As you can see, the drag procedure within Layout view is a very fast and easy way to build your navigation buttons. Note that this drag procedure works only in Layout view.
Figure 15-53. Access creates a new navigation button by dragging a form or report from the Navigation pane to the navigation control.
Why can’t I drag my form or report to the navigation control in Layout view?
If you are using a web form with a navigation control, you cannot drag client forms and client reports to the navigation control. Web forms cannot be bound to or include any client elements. If you try to drag a client form or report into a navigation control on a web form, Access prevents you from completing the procedure. You can, however, drag web forms and web reports into a navigation control on a client form.
Now that you’ve added navigation buttons to the top-level navigation control for two of the database forms, let’s create navigation buttons for the two reports in this database. Select the rptContactAddressBook report in the Navigation pane, drag the report to the right of the frmContactDatasheet navigation button, and then release the mouse. Access creates another navigation button and then displays the report in the subform container. Repeat this procedure one more time by dragging and dropping the rptContactPhoneList report to the right of the rptContactAddressBook navigation button. Open the Property Sheet window and change the captions for the three navigation buttons you just created to Datasheet, Address Book, and Phone List, respectively. Switch to Form view to view your results. Your form up to this point should look like Figure 15-54.
Figure 15-54. You’ve now created four navigation buttons that swap out different forms and reports in the subform container.
Click the navigation buttons and notice how Access swaps out the two forms and two reports in the subform container. You’ll also notice that Access changes the back color and fore color of the selected navigation button to match the background color of the second-level navigation to give a clear visual indication which navigation button you selected. Access does this by utilizing the Back Color, Hover Color, Pressed Color, Hover Fore Color, Pressed Fore Color, and Fore Color properties of the navigation button.
Let’s add a little extra customization to the two report navigation buttons by adding images. Open the Property Sheet window, select the Address Book navigation button, and on the Picture property, select the rptReportPreview shared image from the drop-down list. Access replaces the caption displayed on the navigation button with the shared image of a report icon. We want to include both the caption and the image, so change the Picture Caption Arrangement property from No Picture Caption to General. Access now displays the shared image and the caption on the navigation button. When you select General setting, Access uses the General alignment setting to display the image and text. You can also choose to display the image above, to the right, at the bottom, or to the left of the text. The navigation button is a little wider than it needs to be, so decrease the button’s width by dragging the right edge of the control to the left until it’s just wide enough to display both the shared image and the caption. Repeat these same steps for the Phone List navigation button—change the Picture property to use the same shared image, change the Picture Caption Arrangement property to General, and then resize the control. While you still have the form open in Layout view, reduce the width of the Datasheet navigation button, too. Your form, displayed in Form view and shown in Figure 15-55, is beginning to take shape. Click the Save button on the Quick Access Toolbar and name your form NavigationForm to save your changes. You can find this form saved as frmXmplNavigationForm1 in the sample database.
When you click the Contact List navigation button, Access displays the entire list of contacts in the frmContactList form. Our sample database includes only 32 records, so it’s not too difficult to scroll down the list of contacts. If you have a much larger list of contacts, however, it might be easier to filter the form to display fewer records at a time. We can achieve this functionality by reusing the same form on different navigation buttons, but filtering the form using the Navigation Where Clause property. Instead of displaying extra navigation buttons on the first-level navigation control, it would be more intuitive to display these extra filter buttons in the second-level navigation control beneath the Contact List navigation button.
Switch back to Layout view and then click the Contact List navigation button. Select the frmContactList form in the Navigation pane and then drag the form to the left of the [Add New] navigation button on the second-level navigation control. Access creates a new navigation button on the second-level navigation control that opens this form. Select the frmContactList form in the Navigation pane again and then drag the form to the right of the navigation button you just created on the second-level navigation control. Repeat these steps three more times using the same form until you have a total of five navigation buttons on the second-level navigation control, as shown in Figure 15-56.
Figure 15-56. Add five navigation buttons to the second-level navigation control using the frmContactList form.
When a user clicks the Contact List navigation button in the top-level navigation control, we want to display the entire list of contacts. To make it clear to users that they are looking at the entire list of contacts, we can make the first button in the second-level navigation control unfiltered and change the caption to All. Essentially, the first button in both the first- and second-level navigation controls do exactly the same thing, but we can repeat the functionality so when the user navigates to the other navigation buttons on the second level, they’ll always have a way to view all the records without having to leave the second-level navigation control.
Open the Property Sheet window, select the first navigation button in the second-level navigation control, change the Caption property to All, and resize the navigation button to be 1 inch wide to match the top-level Contact List navigation button. Select the second button navigation button on the second level and change its Caption property to A–G to indicate that clicking this navigation button filters the form to show only contacts with last names that start with the letters A through G. In the Navigation Where Clause property, enter the expression [Last Name]>=“A” And [Last Name]< “H” to limit the records to this range of letters, as shown in Figure 15-57. Note that in the Navigation Where Clause, you do not need to start the expression with an equals sign (=). Reduce the width of this navigation button to one-half of an inch.
Figure 15-57. Change the Navigation Where Clause property to filter the records in the frmContactList form.
Using the example you just learned, make the following changes to the remaining three navigation buttons in the second-level navigation control:
For the third button, change the Caption property to H–M, reduce the width to one-half of an inch, and enter the expression [Last Name]>=“H” And [Last Name]<“N” in the Navigation Where Clause property.
For the fourth button, change the Caption property to N–T, reduce the width to one-half of an inch, and enter the expression [Last Name]>=“N” And [Last Name]<“U” in the Navigation Where Clause property.
For the fifth button, change the Caption property to U–Z, reduce the width to one-half of an inch, and enter the expression [Last Name]>=“U” in the Navigation Where Clause property.
Save your changes to the form, and then switch to Form view to see your completed changes, as shown in Figure 15-58. When you click the first-level Contact List navigation button, you can see all the navigation buttons in the second-level navigation control. When you click the Datasheet, Address Book, or Phone List navigation buttons, you do not see the second-level navigation buttons. When you click the second-level navigation buttons below Contact List, Access filters the records to show only the contacts with last names that start with the letters specified. The second-level navigation buttons are referred to as children of the first-level navigation buttons. If you want to add child navigation buttons below a parent navigation button, you need to select the parent navigation button in Layout view, and then drag forms and reports into the child-level navigation control (or use the [Add New] button to do so). You can find this form saved as frmXmplNavigationForm2 in the sample database.
If you’d like, you can experiment with applying different formatting options to the navigation buttons. Access 2010 includes several new formatting options you can apply to buttons—the new navigation buttons as well as the standard Access command buttons. Switch back to Layout view for your form, select one of your navigation buttons, and then click the Quick Styles button in the Control Formatting group on the Format tab. Access displays a gallery of 42 Quick Styles that you can apply to your button, as shown in Figure 15-59. You can click any of these Quick Styles, and Access changes the colors and styles of your navigation button. By using a Quick Style, you can quickly adjust several color properties of your buttons for a modern look compared to previous versions of Access. When you click a Quick Style, Access changes the Back Color, Border Color, and Fore Color properties to Quick Style to indicate it is using Quick Style formatting properties.
In addition to the Quick Styles, you can choose many other formatting options for buttons under the Shape Effects command. Select a navigation button in one of the navigation controls and then click the Shape Effects command in the Control Formatting group on the Format tab. Access displays a drop-down gallery with four main options—Shadow, Glow, Soft Edges, and Bevel—as shown in Figure 15-60. When you click any of these main options, Access displays additional galleries in a submenu gallery. You can choose many different formatting options from these submenu galleries. For example, you can add different shadow styles to your buttons to give them a three-dimensional look. You can also apply different glow color variations, different levels of soft edging around the borders, and even different styles of beveled edging to your buttons. You can click any of these options and see how they change the appearance of your buttons. If you don’t like an option, you can always undo your last action or click a different formatting option. With all the many new formatting style options for buttons in Access 2010, you might have a hard time trying to decide which options to use!
Figure 15-60. You can choose many shadow, glow, soft edge, and bevel formatting options for buttons in the Shape Effects gallery.
If you try and open a database that contains a client form with a navigation control in Access 2007, Access displays a compatibility warning message in the Business Bar. The warning says that the database uses some features that are incompatible with that version of Access. If you try to open that form in Access 2007 in any view, Access displays an error message indicating it cannot read the data in the form. You cannot edit or work with navigation controls in Access 2007.