USING COMMAND BARS

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.

Figure 20.1. Menus, toolbars, and shortcut menus are the three types of Access command bars available.


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.”

Figure 20.2. CustomerMenu (menu), CustomerToolbar (toolbar), and ModifyMenuWithCode (menu) are all custom 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 Customize Dialog's Toolbars Page

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.

  • Close closes the dialog and saves your changes.

The Customize Dialog's Commands Page

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).

Figure 20.3. Pick and choose the standard commands to include on your command bars.


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.”)

Options Tab of the Customize Dialog

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.

Figure 20.4. The Options page of the Customize dialog allows you to set up how you want your toolbars and menus to behave.


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.

Creating a Toolbar Through the User Interface

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

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).

Figure 20.5. There's not much to creating a newly created toolbar such as this one.


Now that you have the initial toolbar, you can make it useful by adding some commands to it.

Adding Existing Commands to the Toolbar

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.

Figure 20.6. These commands were all placed on this toolbar by using drag and drop.


Specifying Button Groupings

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.

Figure 20.7. By right-clicking a toolbar control, you can get at its individual properties.


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.

Adding a Custom Toolbar Button That Calls Your Own VBA Function

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.


5.
Clear the Shortcut Text text box. Although you could indicate a hotkey by using an ampersand back on the Caption property, and then displaying the key combination in the Shortcut Text property, at this point there's no hotkey using Autokeys set.

6.
Change the ScreenTip text box to read This calls my own command. (This tip is probably longer than what you'll normally use.)

7.
Place a command in the On Action combo box. For this example, use the following statement:

=CallFunctionFromCmdBar()

This function is located in the module modCommandBarRoutines in Chap20.mdb (available on the CD in the ExamplesChap20 folder). This module simply displays a message box. Here is its code:

Function CallFunctionFromCmdBar()

   MsgBox "This function was called from a command bar"

End Function

8.
Change Style to Default Style. This tells Access that whatever command bar type is used, apply the default style for that command bar type. For example, the default style for toolbars is Text Only (In Menus). In addition to Default Style, you can select Text Only (Always), Text Only (In Menus), and Image and Text.

9.
Mark the Begin a Group check box at the bottom of the properties sheet.

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.

Figure 20.9. You've created your own toolbar command.


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.

Creating Menus and Shortcut Menu–Type Command Bars

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.

Adding Command Bars to a Form

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).

Figure 20.11. Access 2000 makes it easy to attach command bars to forms, as shown with the property sheet of the frmShowEachTypeOfControl form.


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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.116.183