You can use the SetMenuItem action to set the state of menu items (enabled or disabled, checked or unchecked) on the custom menu bar or global menu bar for the active window.
Note The SetMenuItem action works only with custom menu bars and global menu bars created by using menu bar macros. The SetMenuItem action is included in this version of Microsoft Access only for compatibility with previous versions. It doesn't work with the new command bars functionality. However, you can use the Enabled and State properties in Visual Basic to disable or enable and check or uncheck items on the new menu bars, toolbars, and shortcut menus.
Setting
The SetMenuItem action has the following arguments.
Action argument | Description |
---|---|
Menu Index | The index of the menu that contains the command for which you want to set the state. Enter an Integer value, starting from 0, for the index of the desired menu in the custom menu bar or global menu bar for the active window. Enter the index value in the Menu Index box in the Action Arguments section of the Macro window. The index is relative to the menu's position in the menu bar macro for the custom menu bar or global menu bar (the position of this menu's AddMenu action in the menu bar macro, counting from 0). The menu bar's display may be somewhat different, since you can use conditional expressions in the menu bar macro to hide or display custom menu items. This is a required argument.
If you select a menu with this argument and leave the Command Index and Subcommand Index arguments blank, you can enable or disable the menu name itself. You can't, however, check or uncheck a menu name (Microsoft Access ignores the Check and Uncheck settings for the Flag argument for menu names). |
Command Index | The index of the command for which you want to set the state. Enter an Integer value, starting from 0, for the index of the desired command in the menu selected by the Menu Index argument. The index is relative to the command's position in the macro group that defines the selected menu for the custom menu bar or global menu bar (the position of this command's macro in the macro group, counting from 0). The menu's display may be somewhat different, since you can use conditional expressions in the menu's macro group to hide or display custom menu commands. |
Subcommand Index | The index of the subcommand for which you want to set the state. This applies only if the desired command has a submenu. Enter an Integer value, starting from 0, for the index of the desired subcommand in the submenu selected by the Command Index argument. The index is relative to the subcommand's position in the macro group that defines the selected submenu for the custom menu bar or global menu bar (the position of this subcommand's macro in the macro group, counting from 0). |
Flag | The state you want to set the command or subcommand to. Click Gray (to disable the command — it appears dimmed), Ungray (to enable it), Check (to place a check by the command — typically indicating it has been selected or toggled), or Uncheck (to remove the check). The default is Ungray. |
Remarks
The SetMenuItem action works only on a custom menu bar or global menu bar for the active window. It doesn't work on the built-in Microsoft Access menu bars, and if the active window doesn't have a custom menu bar or global menu bar, running a macro containing the SetMenuItem action causes a run-time error. Note that a global menu bar, if you've defined one, 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.
You can use this action to set the state of menu commands and subcommands, but not subcommands of subcommands.
To run the SetMenuItem action in Visual Basic, use the SetMenuItem method of the DoCmd object.