Although command bars are very useful, in that you use basically the same method for creating the three types of command bars, they can each be confusing. Figure 20.1 shows all three types of command bars: menus, toolbars, and shortcut menus. You can find this form, frmShowEachTypeOfControl, and the other examples in this chapter in Chap20.mdb, located in the ExamplesChap20 folder on the accompanying CD-ROM.
Note
Notice that the terms shortcut and popup are used in place of one another. They are the same thing.
Note
The shortcut-type menus are available from the Shortcut Menus toolbar shown in the Toolbars list in Figure 20.2, later in the chapter. How to create and use shortcut menus is discussed later in the section “Creating Menus and Shortcut Menu–Type Command Bars.”
Creating different types of command bars in Access 2000 isn't much different from creating toolbars in prior versions. To create the different types of commands in the user interface, from the View menu choose Toolbars and then Customize. The Customize dialog that appears has three page tabs: Toolbars, Commands, and Options.
Note
It seems strange that you would choose the Toolbars option to create menus, but Microsoft didn't want to confuse people by calling them command bars. So command bars are called command bars only when using VBA, and in the user interface the choice is toolbars. In this chapter, I will alternate between calling them command bars and toolbars.
The default page, Toolbars, shows all the toolbars and menus in the current database. Scroll the Toolbars list to see the standard toolbars and your custom toolbars and menus (see Figure 20.2). Toolbars now visible have check marks by their entries.
Note
Although the three custom command bars shown in Figure 20.2 now exist, they will be re-created from scratch for this chapter. These were created ahead of time for your viewing pleasure.
The Shortcut Menus choice in this list is what you use to modify and store the shortcut menu–type command bars. These will be discussed later in this chapter, in the section “Creating Menus and Shortcut Menu–Type Command Bars.” The Toolbars page of the Customize dialog also has these command buttons:
New creates a new command bar.
Rename renames a command bar.
Delete deletes a command bar.
Reset resets a standard command bar to the default commands for that specific command bar.
Properties lets you customize all the command bars (the Toolbar Properties dialog is discussed later, in the section “Adding a Custom Toolbar Button That Calls Your Own VBA Function”).
The Assistant button (with the Question mark) is available to answer your questions.
The Customize dialog's Commands page is where you place individual standard commands on the command bar you're creating. The Categories list contains the various built-in toolbars available in Access. When you select one, the Commands list displays the commands available for that particular toolbar.
When you select a command, the Description button becomes enabled. Click it to display a description of the command being used (see Figure 20.3).
The last button on this page, Modify Selection, is enabled when you click a command on an existing displayed toolbar. Click this button to display the toolbar command's individual property sheet. (This property sheet is discussed later in the section “Adding a Custom Toolbar Button That Calls Your Own VBA Function.”)
The Options page of the Customize dialog contains some options for all the command bar types and how they respond to the user (see Figure 20.4). The first option, Standard and Formatting Toolbars Share One Row, specifies just that: whether to have the standard and formatting toolbars share the same row.
To return to the default set of menu commands, click the Reset My Usage Data button.
The next three options affect only toolbar-type command bars:
Large Icons affects how the icons look on the toolbars.
Show ScreenTips on Toolbars specifies whether to show screen tips for the toolbar buttons.
Show Shortcut Keys on ScreenTips displays the shortcut keys, such as Paste (Ctrl+V).
The last choice, Menu Animations, tells how you want the popup menu portions to pop up. Choices are None, Random, Unfold (left to right and down), and Slide (slides down).
Tip
Actually, the only option worth changing is Show Shortcut Keys on ScreenTips. Unless the user has really bad eyesight, don't select the Large Icons option because it makes really large icons. The Menu Animations options, although cute, are kind of like some sound settings—they can irritate users after a short time.
Now that you're familiar with the tools available to create command bars, it's time to get down to work.
In the following sections, I'll show you how to do six things:
Initially create a custom toolbar
Add existing commands onto the toolbar
Specify groupings of buttons
Add a custom toolbar button that calls your own VBA function
Create menus and shortcut menu–type command bars
Add the command bars to a form
None of these things are too tough to do, but you'll definitely save time and hassles by reading on.
Creating the toolbar itself is probably the easiest process in the Customize dialog:
1. |
Click the New button to open the New Toolbar dialog. |
2. |
Type the name of the new toolbar—for this example, CustomerToolbar. Click OK. |
That's it. After a few moments you see a very small toolbar in the center of your screen, and the toolbar list is updated with the new toolbar selected (see Figure 20.5).
Now that you have the initial toolbar, you can make it useful by adding some commands to it.
Most command bars that you'll create will be made up of commands that already exist in Access via some other menu or toolbar. As a result, it's very convenient to can grab commands from a predefined set from the Customize dialog's Commands page.
Select the View category. Scroll down the Commands list until you see the Close command (refer to Figure 20.3). Click and drag the command from the list onto your new CustomerToolbar. You'll now see the Close command icon on your toolbar.
Now select the Records category. Scroll down the Commands list until you see the First, Previous, Next, and Last commands. Drag these commands on the new toolbar as you did with the Close command. At this point, the toolbar should look like Figure 20.6.
Now that you actually have some buttons on the toolbar, it's time to look at how to group the controls. Let's keep the Close command separate from the other buttons, because it doesn't move records around. To begin a button group, right-click the command that you want to start the new group with—in this case, the First command. When you right-click the command, you will then see the popup menu. Choose Properties from the menu. The properties sheet in Figure 20.7 appears.
This properties sheet provides quite a few ways to manipulate a toolbar button. For now, you're interested in the Begin a Group property. When you click this check box, all that occurs is that a vertical bar appears between the current and prior toolbar buttons. To complete a group, you just check the Begin a Group property on the starting button for the next group.
The purpose of this chapter is to show you programmatic ways of working with command bars, so I'll let you investigate on your own the other commands on this menu, including modifying button faces. Now look at attaching your own routines to a command bar.
There's a very intuitive way to add a custom command to a toolbar. To create a command that calls your code, you need to follow these steps while still in the Customize dialog:
1. |
On the Commands page, select File in the Categories list. |
2. |
From the Commands list, click and drag Custom onto the CustomerToolbar. |
3. |
Right-click the new command button to bring up the shortcut menu, and choose Properties. The properties sheet in Figure 20.8 appears. You can change this property sheet to reflect any of the commands on the current toolbar by changing the selection in the Selected Control drop-down list. Figure 20.8. Change these values to reflect the new custom toolbar command you desire. |
4. |
Change the Caption text box to &My VBA Call. |
Note
Although you're placing a hotkey indicator (&) on a toolbar button, the hotkey will work only if the text is being displayed. These commands are also used on menu-type command bars. This will be true for the next step as well. Because this is a toolbar, the Shortcut Text text box will be disabled.
The properties sheet should now look like Figure 20.9. Notice that the custom button is blank; this is because of the default style chosen. This will be taken care of next.
You're done with the properties sheet. Click the Close button.
The new toolbar button is almost finished, but you need to perform one more task that you'll do just about every time you create a custom toolbar command—change the button's image, also called the button face.
Suppose that you want to change this toolbar button to have the smiley face. To do so, right-click the new toolbar button. Choose Change Button Image from the shortcut menu to see the available images. Choose the smiley face. If you choose to, you can also edit the image in what amounts to a bitmap editor by choosing Edit Button Image from the popup menu. For this example, you're finished with this toolbar. You'll see how to display the toolbar on a specific form later in the “Adding Command Bars to a Form” section.
When you create a menu-type command bar, you place menus for most actions on the main level of the menu. Here's how it works:
1. |
Open the Customize dialog (from the View menu, choose Toolbars and then Customize). |
2. |
Click New on the Toolbars page of the Customize dialog. Fill in the name you want to call the menu and click OK. You've now created the default type of command bar: a toolbar. |
3. |
To change this new command bar to a menu, click Properties in the Customize dialog. The Toolbar Properties sheet appears. (Don't let the name of this properties sheet fool you; it's used for menus as well.) |
4. |
Pull down the Type list to see a list of possible command bar types (see Figure 20.10). Figure 20.10. These properties affect your command bar overall, including the type of command bar it is: toolbar, menu, or popup. |
5. |
Select Menu Bar and then click Close. |
Note
There won't be any visible difference in the command bar itself. At this point, if you want to place a command on the top menu bar, you can do so in the same manner as you did the toolbar-type command bar. Otherwise, read on to place a submenu on the menu bar.
To place a submenu on the new menu, select New Menu from the Categories list on the Customize dialog's Command page. When you select this item, the only command that will appear in the Commands list box is one of the same name: New Menu. Drag and drop this onto your menu bar.
When you click New Menu on your menu bar, a placeholder appears for your first command on the submenu. Using the techniques described earlier in the chapter, you can drag and drop commands onto the submenu—and add your own as well.
To change the submenu's caption, right-click the command and choose Properties. Then change the Caption property to reflect the name of the submenu you desire.
To create a shortcut-menu–type command bar, leave the command bar in the toolbar style until you've completed it. Then use the Toolbar Properties sheet (which you access from the Customize dialog) to change the Type to Popup.
To get to the shortcut toolbar for modification, you must choose Shortcut Menus from the Toolbars list on the Customize dialog's Toolbars page. This will display all the shortcut menus that exist on a menu, where you can then customize them. Your custom shortcut menus will show up beneath the Custom item, which is the last on the left.
Using all three types of command bars with forms is fairly straightforward in Access 2000. (In versions before Access 97, you had to use a macro or code to activate toolbars with forms.) You can specify the names of all three types of command bars on the Other page of the Form property sheet (see Figure 20.11).
To specify the various types of command bars to use, simply fill in the name of the corresponding command bar in the property of the form, as shown in Figure 20.11 with the Menu Bar, Toolbar, and Shortcut Menu Bar properties.
18.217.116.183