ACC97: Error Creating CommandBar with Duplicate Name

Last reviewed: May 21, 1997
Article ID: Q162822
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multi-user skills.

If you try to create a command bar with an existing name through 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 through 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 97 file, except in Microsoft Word 97.

STATUS

This behavior is by design.

MORE INFORMATION

The following table demonstrates how the Microsoft Office 97 applications behave when creating duplicate command bar names:

 Application              Using Code      Using the User Interface
 -----------------------------------------------------------------

 Microsoft Word 97           Yes                    No
 Microsoft Excel 97           No                    No
 Microsoft Access 97          No                    No
 Microsoft Powerpoint 97      No                    No

NOTE: Microsoft Word 97 is able to create multiple command bars with the same name through Visual Basic for Applications because Word needs to be able to have multiple command bars with the same name to handle the case where you have two templates open.

Steps to Reproduce Behavior Using Visual Basic for Applications

  1. Using Microsoft Access 97, 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:

          Option Explicit
    

  3. Type the following procedure:

          Function CreateCmdBar()
    
              Dim cb As CommandBar
              Set cb = Application.CommandBars.Add("Test1")
              Set cb = Application.CommandBars.Add("Test1")
          End Function
    
    

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

           ?CreateCmdBar()
    

    Note that you receive the following error message on the third line of code:

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

Steps to Reproduce Behavior Using the User Interface

  1. Using Microsoft Access 97, 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" (without the quotation marks), and then click OK.

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

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

REFERENCES

For more information about creating command bars through code, search the Help Index for "Add Method, command bars," and then "Add Method, (CommandBars Collection)."

For more information about creating command bars through the user interface, ask the Microsoft Office 97 Office Assistant, "How do I create a command bar."


Additional query words: menubar toolbar menu shortcut xl excel access word
powerpoint
Keywords : GnlOthr kberrmsg kbui UifMenub
Version : 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution 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: May 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.