Building Toolbars, Menus, and Shortcut Menus


Building Toolbars , Menus, and Shortcut Menus


What is a toolbar? A toolbar is primarily a collection of buttons or text and can occasionally include other controls such as combo boxes and text boxes. A toolbar can be organized horizontally, vertically, or in a floating rectangle. Its appearance in the Access window depends on whether it is defined as a menu, a toolbar, or a shortcut menu. Because menu bars and shortcut menus are just different types of toolbars, you can customize all three the same way. Though you probably will be very familiar with toolbars and menus, you may not be conversant with the terminology. Figure 7-1 illustrates the different types of toolbars. These are:

  • A horizontal menu bar that runs across the window with commands such as File, Edit, and View.

  • A vertical menu bar with commands such as New Database and Open Database. The vertical menu bar will normally be attached to a menu bar.

  • A toolbar, which is a collection of buttons and sometimes text, that can be organized in rectangles anywhere within the Access window. Sometimes you can position toolbars next to each other in the same row. Sometimes multiple toolbars may not fit into the space across or down the screen but are flexible enough that users can generally place them where they want in the Access window.

  • A special vertical menu called a shortcut menu (or pop-up menu). This menu appears when you right-click a form, report, other objects, and some form controls.

click to expand
Figure 7-1: Menus, toolbars, and shortcut menus.

Menus and toolbars behave in different ways in your application, depending on whether or not Microsoft developed it. Menus placed on your computer at the same time as the Access installation are called built-in menus. You can customize built-in menus on your computer, and these changes will never appear on any other computer. Therefore, you have to be aware that manually modifying built-in menus will not provide much protection for your database.

A custom menu is a menu or toolbar that you create for your application. Custom menus allow you to create a user interface within your own Access database that has the look and feel of a Microsoft Windows application. If you create a custom menu for a database, that menu will be available only within that database. It is possible to share menus and toolbars between databases by referencing another database, but I advise sharing only if you are using the referenced database as a code library. Within the menu environment you can create, delete, and rename your own custom toolbars, menu bars (including submenus), and shortcut menus.

Building a Custom Toolbar Menu

The easiest custom menu that you can add to your database is a toolbar. The first custom toolbar that you should design for your database is one to replace the built-in Form View toolbar. This built-in toolbar has a number of developer-specific commands (such as Design View and Database Window). Therefore, if you create a version that is suited to users, this custom toolbar will protect your application and reduce clutter by removing a number of buttons from your user interface.

Now I will show you the steps to create a custom toolbar. The purpose of the toolbar will be to provide users with buttons that are suited to forms with records. For these instructions, I will use a copy of the Northwind database, and I suggest that you do likewise.

  1. First, open the Customize dialog either by choosing View ˜ Toolbars ˜ Customize, as shown in Figure 7-2, or by right-clicking any toolbar or menu and choosing Customize, as shown in Figure 7-3.

    click to expand
    Figure 7-2: Customizing toolbars by using the View menu.

    click to expand
    Figure 7-3: Customizing toolbars by right-clicking.

  2. When the Customize dialog opens, select the Toolbars tab, click New, and give your toolbar a name , such as mnuRecords (as shown in Figure 7-4). Click OK.

    click to expand
    Figure 7-4: Naming a new custom toolbar.

  3. A small, blank toolbar will appear near the Customize dialog. Select the Commands tab so that you can add some of the built-in commands to your new toolbar (as shown in Figure 7-5).

    click to expand
    Figure 7-5: Selecting the commands that you need for your toolbar.

  4. It is probably a good idea at this stage to open another Access database in another window and look at the Form View toolbar. From this second database, you can now decide which of the commands you need for your new custom toolbar.

  5. Rummage through the different lists to find the commands that you want. Your focus here should be to choose those buttons that your users will need to work with the data in the database, but not those commands that allow users to modify the design of the objects in the database. You will find most of the Form and Report View- related commands in the list next to the Edit, View, and Records categories.

  6. To add a command to the new toolbar, drag and drop it onto the toolbar.

  7. If you add the wrong command or want to eliminate an existing command, drag and drop the button from the new toolbar to a blank part of the Access window. This action deletes the button.

Once you have dragged all the relevant built-in commands to your new toolbar, you can modify the look of the toolbar buttons by right-clicking the command (as shown in Figure 7-6). One useful addition to a toolbar is the Begin a Group command. This command adds a line that subdivides the toolbar. As you can see, there are plenty of options to modify your toolbar. My thoughts on toolbar visual changes are that these modifications should not stray too far from the conventions used in Microsoft Access or other popular Windows software.

click to expand
Figure 7-6: Adding a separator with the Begin a Group command.

Now, if you right-click any toolbar, you will see the name of the custom toolbar that you have created. Click it to display or hide the toolbar. In the next section, I will show you how to build a custom menu.

Building a Custom Menu

Building custom menus is a good way to protect your database and make it easier to use at the same time. A custom menu can be either a simple structure that provides access to the top hierarchy of objects in your database, a full user interface that replaces the more conventional buttons on forms, or the interface provided by the Switchboard Manager wizard in Access 2000 or later.

When it comes to building menus, the techniques are very similar to those used for building toolbars. Once again, I will combine descriptions with a pictorial representation because I find that this best illustrates the subtle tricks required to put the menu together.

  1. In your copy of the Northwind database, open the Customize dialog, select the Toolbar tab, and create a new toolbar.

  2. Click the Toolbar Properties button and change the Type to Menu Bar, as shown in Figure 7-7.


    Figure 7-7: Converting a toolbar to a menu bar.

    Tip  

    The Toolbar Properties dialog shows the selected toolbar options in a drop-down list. Make sure first that you are indeed using the correct toolbar. If you have selected the wrong toolbar, you can use the drop-down list to change your selection.

  3. After you have changed the toolbar to a menu bar, the toolbar will look different, as shown in the Access 2002 sample in Figure 7-8.

    click to expand
    Figure 7-8: Dragging New Menu to the menu bar.

  4. Close the Toolbar Properties dialog and switch to the Commands tab. You have two options when building your new menu. If you drag the commands (like Open form) across to the menu bar, they will line up horizontally across the menu bar. The second and more likely choice is to make a vertical menu, which you can do by dragging the New Menu command to your menu bar (shown in Figure 7-8).

  5. Right-click the new menu item and rename the menu to "&Northwind."

    Tip  

    You can create an accelerator key for your menu item so that users can access it with the keyboard. To do so, type an ampersand (&) in front of the letter that you want to use. For example, to use "N" as the accelerator key for the Northwind menu, type "&Northwind." The "N" in your command name is underlined , and users can carry out the command by pressing ALT+N.

  6. Now we are going to add a form to this menu and, believe me, it isn't all that obvious what you have to do. While the Customize dialog is still open, on the Commands tab, select the All Forms category (as shown in Figure 7-9).

    click to expand
    Figure 7-9: Adding a form to a custom menu.

  7. Select the Main Switchboard form command, drag it to the Northwind menu, and hover over the menu until a blank toolbar appears directly under it. Then drop the Main Switchboard button onto the blank toolbar.

  8. If you are using Access 2002, you might want to right-click the new menu bar and clear the Type a Question for Help check box.

  9. Close the Customize dialog, and try out your new menu.

While you're in the Customize dialog, you might also want to add some other forms from the Commands form to your menu. Remember to hover above the menu (Northwind) when you drag the command from the Commands tab in the Customize dialog.

Before rushing off and spending lots of time enhancing menu bars, remember that you should avoid duplicating too many commands in both your forms and the menu system because it may prove difficult to synchronize both systems. I suggest that if you want to build a comprehensive system of menus, you should avoid having too many equivalent buttons in the forms themselves . In the applications in which I have used menus (as in Figure 7-10), I found that it is best to avoid anything more than top-level forms in your custom menu bars. Most Access users who I have dealt with like to see the options on a form rather than tucked away in menus at the top of the Access window.


Figure 7-10: A custom menu for the Northwind database.

In the next section, we will look at another type of toolbar that the Microsoft Office toolbars environment supports.

Building a Shortcut Menu

A shortcut (pop-up) menu appears whenever you right-click a form or a report in preview mode. If you leave the built-in menus in place, the shortcut menu will include the Design View command. Naturally, you probably won't want this command to be available in a protected database, so let's find out how to build a custom shortcut menu that replaces the built-in Form View shortcut menu:

  1. Open the Customize dialog, select the Toolbars tab, and create a new menu.

  2. Click the Properties button and select Popup from the Type drop-down list. This action brings up a message box, shown in Figure 7-11, that tells you that the menu is about to disappear and that you will have to find it again. Weird, but true!

    click to expand
    Figure 7-11: The message invoked when you make a toolbar into a shortcut (pop-up) menu.

  3. Click OK and then click Close.

  4. To start adding commands to your new shortcut menu, choose the Toolbars tab.

  5. Select the Shortcut Menus check box (as shown in Figure 7-12). Find the new shortcut menu under the Custom menu on the right side of the Shortcut Menus bar.

    click to expand
    Figure 7-12: Displaying shortcut menus with other toolbars.

  6. Now that you have found the new shortcut menu, you can drag and drop all the record and form-related commands onto the menu, such as the Form View menu that I have built in Figure 7-13.

    click to expand
    Figure 7-13: A demonstration of a Form View shortcut menu.

Whenever you want to edit the shortcut menu further, you need to open the Customize dialog, select the Toolbars tab, and select the Shortcut Menus check box. Alternatively, you can find your shortcut menu by selecting the menu you want with the drop-down list at the top of the Toolbars tab.

Tip  

At the bottom of your keyboard, you will probably find a special key called the Shortcut key, which has a small picture of a vertical menu with an arrow. Pressing this key has the same effect as right-clicking.

Adding Your Functions to Your Toolbars

Throughout this chapter, the toolbar discussions focus on protecting your database by replacing or disabling built-in Access commands. These discussions gloss over the fact that one of the strengths of the Access toolbars (and menus) is that you can add custom toolbar commands that run your own VBA functions or macros.

I will now illustrate how this works:

  1. Create and save a new module with the very simple function that follows . This function will display the startup options from the Tools menu.

     Function showStartupOptions()    ' Show the startup option dialog.    RunCommand acCmdStartupProperties End Function 
  2. Select the Customize dialog box, select the Toolbars tab, and choose an existing toolbar.

  3. Select the Commands tab and choose the File category.

  4. Drag the Custom command across to your toolbar.

  5. Right-click the Custom command and choose Properties.

  6. In the On Action box, type an expression to run your VBA function. The expression must use the following syntax: =functionname() . For our startup options function, type =showStartupOptions() . You can also use the On Action drop-down list to select a macro, if you want to.

If you start to rely on toolbars a lot in your application, you may want to investigate other toolbar properties, such as:

  • Adding help information to menu items.

  • Protecting changes to toolbars, such as movement and resizing.

As previous demonstrations have shown, building the different types of toolbars is a graphical process with a few tricks here and there. Fortunately, the results are high quality and should improve your Access user interface. In the next section, I'll show you how to add custom toolbars to your application so that they appear when you want them.




Real World Microsoft Access Database Protection and Security
Real World Microsoft Access Database Protection and Security
ISBN: 1590591267
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net