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.
The SetMenuItem action uses 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. 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 with 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 with 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. You can select Gray to disable the command (so 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. |
The SetMenuItem action works only on a custom menu bar or global menu bar for the active window. It does not work on the built-in Microsoft Access menu bars, and if the active window does not 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 have defined one, 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.
You can use this action to set the state of menu commands and subcommands, but not subcommands of subcommands.
You can use the SetMenuItem action to temporarily set the state of a Microsoft Access menu command (put into the custom menu using the DoMenuItem action). However, as soon as Microsoft Access refreshes the menu, the command returns to its normal state. For example, if you use the SetMenuItem action to disable a custom menu command that maps to the Cut command on the Edit menu, the command is automatically enabled again when you select a piece of text.
To run the SetMenuItem action in Visual Basic, use the SetMenuItem method of the DoCmd object.
AddMenu Action, DoMenuItem Action, MenuBar Property, SetMenuItem Method.