Placing Custom Commands on Menus and Toolbars

3 4

In addition to dragging built-in commands to toolbars and menus, you can add your own functions and macros to toolbars and menus so that you can execute the macros and functions by clicking buttons or selecting menu commands. For example, let’s say you’ve created a macro to run a series of actions needed to import and process data from a mainframe and a function to track down and delete partial records from a table. You can create toolbar buttons to run the macro and the function with a single click.

To create a toolbar button that runs a macro, follow these steps:

  1. Open the Customize dialog box by right-clicking the gray background of a toolbar and selecting Customize from the shortcut menu.
  2. Click the Commands tab, and then select All Macros in the Categories list.
  3. Locate the macro in the Commands list, and drag it to the desired location on the toolbar of your choice, as shown in Figure 13-3.

    figure 13-3. create a toolbar button that runs a macro by dragging the macro to a toolbar.

    Figure 13-3. Create a toolbar button that runs a macro by dragging the macro to a toolbar.

  4. By default, the toolbar button has a small scroll image and the name of the macro. To display an image only, right-click the button to open its shortcut menu, and select Default Style. To give the button a shorter caption, edit the name in the Name property shown on the shortcut menu.

The technique for creating a toolbar button to run a function is somewhat more complicated. To place a button that executes a function on a toolbar, follow these steps:

  1. Open the Customize dialog box by right-clicking the gray background of a toolbar and selecting Customize from the shortcut menu.
  2. Click the Commands tab of the Customize dialog box.
  3. Select File in the Categories list.
  4. From the Commands list, drag the Custom command to the toolbar, creating a new, blank toolbar button.
  5. Right-click the new Custom button, and then select Properties from the shortcut menu to open the control’s properties sheet.
  6. Type the name of the function in the On Action combo box, preceded by an equal sign, as shown in Figure 13-4.

    Figure 13-4. Assign a function to a toolbar button by entering its name as the button’s </i>On Action<i> property.

    Figure 13-4. Assign a function to a toolbar button by entering its name as the button’s On Action property.

    note


    The drop-down list for the On Action combo box displays only macros, so you can’t use it to select a function.

  7. Change the button’s name in the Caption text box.
  8. Change the text in the ScreenTip box to describe the button’s function.
  9. Change the button style and any other properties in the properties sheet. (This step is optional.)
  10. Click OK to close the properties sheet.

note


You can place only functions on toolbar buttons—this technique doesn’t work for subroutines.

Figure 13-5 shows two new buttons (one button runs a macro, and the other runs a function) on the Database toolbar, with the ScreenTip for the button that runs the function.

figure 13-5. one of these toolbar buttons runs a macro; the other runs a function.

Figure 13-5. One of these toolbar buttons runs a macro; the other runs a function.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

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