Microsoft Knowledge Base Email Alertz

If you try to use the CommandBars object model in Visual Basic for Applications to reference the Shortcut Menus toolbar, you may receive the following error message: Run-time error '5': Invalid procedure call or argument

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 208444 - Last Review: October 11, 2006 - Revision: 2.2

ACC2000: Can't Access ShortCut Menus CommandBar from Code

This article was previously published under Q208444
Advanced: Requires expert coding, interoperability, and multiuser skills.

On This Page

SYMPTOMS

If you try to use the CommandBars object model in Visual Basic for Applications to reference the Shortcut Menus toolbar, you may receive the following error message:
Run-time error '5': Invalid procedure call or argument

CAUSE

You can't use Visual Basic for Applications to reference the Shortcut Menus toolbar. It is the only toolbar that is not available by 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.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. 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 in the Toolbar Properties dialog box. Click Close in 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 Immediate 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 Immediate 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 shortcut menus, click Microsoft Access Help on the Help menu, type work with menu bars and shortcut menus in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

APPLIES TO
  • Microsoft Access 2000 Standard Edition
Keywords: 
kberrmsg kbprb kbprogramming KB208444
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate