AddMenu Action

Description

The AddMenu action can be used 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.
  • Create 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.
  • Create a global menu bar. The global menu bar replaces the built-in menu bar for all Microsoft Access windows, except where you have added a custom menu bar for a form or report.
  • Create a global shortcut menu. The global shortcut menu replaces the built-in shortcut menu for all Microsoft Access windows, except where you have added a custom shortcut menu for a form, form control, or report.

Setting

The AddMenu action uses 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. 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.
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, 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 Shortcut 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.

Tip You can use the Menu Builder to create any of the custom or global menu bars and shortcut menus by clicking the Build button next to the property box or Startup dialog option box where you specify the menu bar macro. The Menu Builder creates and names the menu bar macro and the macro groups containing the actions for the menu commands and subcommands on the menu you create. If you use the Menu Builder to create the menu bar macro and the macro groups for the menus, you can also use the Menu Builder to edit these macros and macro groups.

However, if you create the custom menu bar or custom shortcut menu in the Macro window, you can’t use the Menu Builder to edit the menu bar macro and macro groups because the Menu Builder places restrictions on the names it uses for the menu bar macro and macro groups, and on the kinds of actions it uses in the macros.

For global shortcut menus and custom shortcut menus, add only one menu in the Menu Builder. Any additional menus are ignored.

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

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 Menu Name and Status Bar Text columns of such an AddMenu action 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.

Note In Microsoft Access version 2.0, if you used the AddMenu action to put the Add-Ins submenu on the File menu of a custom menu bar, Microsoft Access automatically added the appropriate Add-Ins submenu items to your custom menu. In Microsoft Access for Windows 95, the Add-Ins submenu has moved to the Tools menu. Microsoft Access adds the submenu items to this menu as before. However, it will not add the submenu items to an Add-Ins submenu on the File menu of a custom menu bar or global menu bar. If you had an Add-Ins submenu on one or more of your custom menu bars in version 2.0, you may want to rewrite your macros and move the Add-Ins submenu to the Tools 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.