ACC2000: Error Creating CommandBar with Duplicate Name

ID: Q208715


The information in this article applies to:


SYMPTOMS

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

If you try to create a command bar with an existing name by using Visual Basic for Applications, you may receive the following error message:

Run-time error '5':
Invalid procedure call or argument
If you try to create a command bar with an existing name by using the user interface, you may receive the following error message:
A toolbar named '<name>' already exists. Type another name.


RESOLUTION

You cannot create multiple command bars with the same name in any Microsoft Office file, except in Microsoft Word.


MORE INFORMATION

Only Word is able to create multiple command bars with the same name through Visual Basic for Applications because Word needs the ability to have multiple command bars with the same name when two templates are open.

Steps to Reproduce Behavior by Using Visual Basic for Applications

  1. Open the sample database Northwind.mdb.


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


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
    Function CreateCmdBar()
       Dim cb As CommandBar
       Set cb = Application.CommandBars.Add("Test1")
       Set cb = Application.CommandBars.Add("Test1")
    End Function 
  6. To test this function, type the following line in the Immediate window, and then press ENTER:
    
    ?CreateCmdBar() 
    Note that you receive the following error message on the third line of code:


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

Steps to Reproduce Behavior by Using the User Interface

  1. Open the sample database Northwind.mdb.


  2. On the View menu, point to Toolbars, and then click Customize.


  3. Click the New button in the Customize dialog box. Set the Toolbar name to Test2, and then click OK.


  4. Repeat step 3. Note that you receive the following error message:


  5. A toolbar named 'Test2' already exists. Type another name.


REFERENCES

For more information about creating command bars through code, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "Add Method, command bars" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about creating command bars through the user interface, click Microsoft Access Help on the Help menu, type "command bars" in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Additional query words: menubar toolbar menu shortcut xl excel access word powerpoint


Keywords          : kberrmsg kbui kbdta GnlOthr 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 13, 1999