ACC97: Unable to Disable Custom Menu by Using SetMenuItem Action

ID: Q189902


The information in this article applies to:


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you run a macro that uses the SetMenuItem to disable a custom menu option, the action fails.


RESOLUTION

To work around this behavior, you can use the SetMenuItem method from within a Visual Basic for Application procedure, as illustrated by the following line of code:


   DoCmd.SetMenuItem 0,1,,acMenuGray 

-or-

You can use the properties and methods of the CommandBars collection to manipulate and customize both built-in and custom menus.

For additional information about using Visual Basic for Applications to

modify command bars, please see the following article in the Microsoft Knowledge Base:

Q160293 ACC97: How to Dim Menu Items or Disable Toolbar Buttons in code


MORE INFORMATION

Steps to Reproduce Behavior


  1. Create a new database named MenuTest.mdb.


  2. Create the following macro and save it as AddMenu:
    
          Macro Name             Action
          ------------------------------
                                 AddMenu
    
          AddMenu Action Arguments
          ------------------------
                Menu Name: Menu
          Menu Macro Name: Menu
          Status Bar Text: 


  3. Create the following macro and save it as Menu:
    
          Macro Name             Action
          -----------------------------
          Beep                   Beep 


  4. Create the following macro and save it as GrayMenu:
    
          Macro Name             Action
          ----------------------------------
                                 OpenForm
                                 SetMenuItem
    
          GrayMenu Action Arguments
          -------------------------
                Form Name:  Form1
                     View:  Form
              Filter Name:
          Where Condition:
                Data Mode:
              Window Mode: Normal
    
          SetMenuItem Action Arguments
          ----------------------------
                Menu Index: 0
             Command Index: 0
          Subcommand Index:
                      Flag: Gray 


  5. Create a new blank form in Design view and save it as Form1.


  6. Set the MenuBar property of the form to AddMenu, and add the following command button to the detail section of the form:
    
          Command Button:
          -----------------------
             Name: CmdDimMenu
          Caption: Gray Menu Item
          OnClick: GrayMenu 


  7. Open the form in form view, and click the command button.


Note that the menu item "Menu" is not disabled.


REFERENCES

For additional information about command bars, search for "CommandBars collection" using the Microsoft Access Help menu.

Additional query words: grayed unavailable dimmed greyed gray grey


Keywords          : kbdta McrProb McrActn 
Version           : WINDOWS:97
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: April 26, 1999