AddMenu Action

Description

You can use the AddMenu action to create:

  • A custom menu bar for a form or report. The custom menu bar replaces the built-in menu bar for the form or report.
  • A custom shortcut menu for a form, form control, or report. The custom shortcut menu replaces the built-in shortcut menu for the form, form control, or report.
  • A global menu bar. The global menu bar replaces the built-in menu bar for all Microsoft Access windows, except where you've added a custom menu bar for a form or report.
  • A global shortcut menu. The global shortcut menu replaces the built-in shortcut menu for fields in table and query datasheets, forms in Form view, Datasheet view, and Print Preview, and reports in Print Preview, except where you've added a custom shortcut menu for a form, form control, or report.
Note While you can still create all these types of custom menus by using macros containing AddMenu actions in Microsoft Access 97 (and any existing custom menus you've created by using macros will still work), it's recommended that you create them by using the Customize dialog box, available by pointing to Toolbars on the View menu and clicking Customize. While the Customize dialog box is displayed, you can easily create a new menu or customize a built-in menu.

Setting

The AddMenu action has the following arguments.

Action argument

Description

Menu Name

The name of the drop-down menu to add to the custom menu bar or global menu bar. Enter the menu name in the Menu Name box in the Action Arguments section of the Macro window. This is a required argument for custom menu bars and global menu bars. This argument is ignored for custom shortcut menus and global shortcut menus.

To create an access key so that you can use the keyboard to choose the menu, type an ampersand (&) before the letter you want to be the access key. This letter will be underlined in the menu name on the menu bar.

Menu Macro Name

The name of the macro group that contains the macros for the menu's commands. This is a required argument.

If you run a macro containing the AddMenu action in a library database, Microsoft Access looks for the macro group with this name in the current database only.

Status Bar Text

The text to display in the status bar when the menu is selected. This argument is ignored for custom shortcut menus and global shortcut menus.


Remarks

To create a custom menu bar, a custom shortcut menu, a global menu bar, or a global shortcut menu by using macros, you must do the following:

  1. Create a menu bar macro that contains an AddMenu action for each drop-down menu you want on the custom menu bar or global menu bar. For custom shortcut menus and global shortcut menus, the menu bar macro should contain just one AddMenu action.
  2. Assign commands to each drop-down menu by creating a macro group for each menu. Each command runs the set of actions defined by a macro in this macro group. For custom shortcut menus and global shortcut menus, create just one macro group in which each macro contains the set of actions for one of the commands in the shortcut menu.
  3. Attach the menu bar macro to the appropriate Microsoft Access object: For custom menu bars, enter the name of the menu bar macro in the MenuBar property for the form or report.

    For custom shortcut menus, enter the name of the menu bar macro in the ShortcutMenuBar property for the form, form control, or report.

    For global menu bars, click Startup on the Tools menu, then in the Startup dialog box enter the name of the menu bar macro in the Menu Bar box.

    For global shortcut menus, click Startup on the Tools menu, then in the Startup dialog box enter the name of the menu bar macro in the Shortcut Menu Bar box.

Each menu on the menu bar requires a separate AddMenu action.

The custom and global menu bars and shortcut menus replace the built-in menu bars and shortcut menus for the objects they're attached to. If you want to retain certain Microsoft Access commands to use on these menus, use the RunCommand action to put the commands into the macro groups for the desired menus.

You can run a macro from a menu command by using the RunMacro action in the macro for the command.

Note AddMenu actions can be used only in a menu bar macro specified by the MenuBar or ShortcutMenuBar property of a form, form control, or report, or by the Menu Bar box or Shortcut Menu Bar box in the Startup dialog box, available by clicking Startup on the Tools menu. Menu bar macros should contain only AddMenu actions.

When you specify a menu bar macro for a form or report or for the database, Microsoft Access runs this menu bar macro whenever the form, report, or database is opened. If you make changes to the menu bar macro or the macro groups that define the commands on the drop-down menus while the form, report, or database is open, you must close the form, report, or database and reopen it to see the changes in the custom menu bar and its menus.

When you are creating the macro groups that contain the commands for a custom menu, the following information applies:

  • In the macro group, the name in the Macro Name column for each macro will be the command name. The text in the Comment column in that row will appear in the status bar when you choose the command.
  • To create a line between two menu commands, type a hyphen (-) in the Macro Name column between the appropriate menu commands.
  • To create an access key so that you can use the keyboard to choose the command, type an ampersand (&) before the letter you want to be the access key in the command name. This letter will be underlined on the menu.
You can create a submenu for a custom menu or a custom shortcut menu by using the AddMenu action in a macro group specified by the Menu Macro Name argument. If you put an AddMenu action in such a macro group, Microsoft Access creates a submenu with the menu name and status bar text specified by the Menu Name and Status Bar Text arguments for this AddMenu action. The submenu contains the commands defined by the macros in the macro group specified by the Menu Macro Name argument for the AddMenu action. The Macro Name and Comment columns of such an AddMenu action (which normally specify the command name and status bar text for a command on the custom menu) are ignored, since this action defines a submenu, not a command on the top-level menu. You can create multiple levels of submenus by using AddMenu actions in the macro groups for each level of menu.

Macro conditions are supported in the top-level menu bar macro only. In other words, you can use a condition in a menu bar macro to determine if a particular menu will be displayed on the custom menu bar or global menu bar, but only for the menus on the top level of the menu bar. You can't use conditions to display or hide commands or submenus on the menus. You can also use a condition to hide or show a custom shortcut menu or global shortcut menu.

The AddMenu action isn't available in Visual Basic. You can, however, set the MenuBar or ShortcutMenuBar property in Visual Basic to attach a custom menu bar or custom shortcut menu to a form, form control, or report. You can set the StartupMenuBar property (the programmatic equivalent of setting the Menu Bar box) to create a global menu bar. You can also set the MenuBar property of the Application object to create a global menu bar. Similarly, you can set the StartupShortcutMenuBar property (the programmatic equivalent of setting the Shortcut Menu Bar box) or the ShortcutMenuBar property of the Application object to create a global shortcut menu.

See Also

Application object, Event properties, MenuBar property, ShortcutMenuBar property, StartupMenuBar property, StartupShortcutMenuBar property.