ACC97: Can't Access ShortCut Menus CommandBar from Code

Last reviewed: August 29, 1997
Article ID: Q162456
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

If you try to reference the Shortcut Menus toolbar using the CommandBars object model in Visual Basic for Applications, you may receive the following error message:

   Run-time error '5':
   Invalid procedure call or argument

CAUSE

You can't reference the Shortcut Menus toolbar using Visual Basic for Applications. It is the only toolbar that is not available using Visual Basic for Applications.

RESOLUTION

Although you cannot reference the Shortcut Menus toolbar through code, you can reference any custom shortcut menu through code. If you want to programmatically modify a custom shortcut menu through code, you will need to make a reference to the specific shortcut menu you are trying to change. This article demonstrates how to create a custom shortcut menu and then how to reference it using Visual Basic for Applications.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.

To create and reference a custom shortcut menu using Visual Basic for Applications, follow these steps:

  1. Open the sample database, Northwind.mdb, and on the View menu, point to Toolbars, and click Customize.

  2. In the Customize dialog box, on the Toolbars tab, click New.

  3. In the New Toolbar dialog box, type MyCustomShortCut in the Toolbar Name box. Click OK.

    NOTE: A new toolbar appears in the Customize dialog box.

  4. In the Customize dialog box, on the Toolbars tab, click Properties.

  5. In the Toolbar Properties dialog box, make sure MyCustomShortcut is selected in the Selected Toolbar list. In the Type list, click Popup. Click OK on the informational message displayed.

  6. Click Close on the Toolbar Properties dialog box. Click Close on the Customize dialog box.

  7. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  8. Type the following procedure in the module:

          Function RefShortcut()
    
             Dim cb as CommandBar
             Set cb = CommandBars("MyCustomShortcut")
             Msgbox cb.Name
          End Function
    
    

  9. To test this function, type the following line in the Debug window, and then press ENTER:

          ?RefShortcut()
    

Note that the message box opens and displays the name of the custom shortcut menu.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  2. Type the following procedure in the module:

          Function Test()
    
             Dim cb as CommandBar
             Set cb = CommandBars("Shortcut Menus")
             Msgbox cb.Name
          End Function
    
    

  3. To test this function, type the following line in the Debug window, and then press ENTER:

           ?Test()
    

    Note that you receive the following error message:

          Run-time error '5':
          Invalid procedure call or argument
    

REFERENCES

For more information about custom shortcut menus, search the Help Index for "shortcut menus, creating," or ask the Microsoft Access 97 Office Assistant.


Additional query words: Word Powerpoint commandbar context command bar bars
Keywords : DcmHlp kberrmsg kbprg
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb
Solution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.