Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Only One Menu Bar Can Be Visible at a Time Using Code


View products that this article applies to.

This article was previously published under Q207157
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Symptoms

When you create a new menu bar in Visual Basic for Applications code, or when you set the Visible property of an existing menu bar to True, the current menu bar is no longer visible. However, if you create a new menu bar or view an existing menu bar by clicking the View menu, pointing to Toolbars, and then clicking Customize, both the current menu bar and the new one remain visible.

↑ Back to the top


Resolution

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. You can set the Visible property of any existing menu bar in code to make it visible, but this method only allows you to display one menu bar at a time. When you set the Visible property of any menu bar to True, Microsoft Access automatically sets the Visible property of all other menu bars to False.

For example, assume your database contains two menu bars: MenuBar1 and MenuBar2. If MenuBar1 is displayed on your screen, the following line of code automatically sets the Visible property of MenuBar1 to False:
CommandBars("MenuBar2").Visible = True
				
If MenuBar2 is displayed on your screen, the following line of code automatically sets the Visible property of MenuBar2 to False:
CommandBars("MenuBar1").Visible = True
				
In order to display more than one menu bar at a time, you must create your new menu bar or view an existing one through the user interface as follows:
  1. On the View menu, point to Toolbars, and then click Customize.
  2. In the Customize dialog box, click an existing menu bar, or click New to create a new one.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Create a new module.
  3. On the Tools menu, click References.
  4. In the References dialog box, click Microsoft Office 9.0 Object Library, and then click OK. If the reference is not listed in the Available References box, click the Browse button and search for the file, Mso9.dll.
  5. Type the following line in the Declarations section of your module:
    Public strCurrentMenuName As String
    					
  6. Type the following procedure:
    '*******************************************************************
    
    ' This procedure creates a new menu bar and makes it visible.
    
    '*******************************************************************
    
    Sub CreateMenuBar(strNewMenuName as String)
    Dim cmdNewMenu As CommandBar
    
    ' Set Global strCurrentMenuName to existing menu for use later when
    ' toggling.
    strCurrentMenuName = CommandBars.ActiveMenuBar.Name
    
    ' Create a new menu bar.
    Set cmdNewMenu = Application.CommandBars.Add(strNewMenuName, _
       msoBarFloating, True, False)
    With cmdNewMenu
      ' Set Protection property to no protection so users can customize
      ' it.
      .Protection = msoBarNoProtection
      ' Show new menu.
      .Visible = True
    End With
    End Sub
    					
  7. To test this function, type the following line in the Immediate window, and then press ENTER:
    CreateMenuBar "ExampleMenu"
    						
    When you minimize the Visual Basic Editor you that see a new floating menu bar is displayed on the screen, and that the original menu bar is hidden from view.

    NOTE: All command bars require a unique name. If you use the name of an existing command bar in the strNewMenuName argument of this procedure, you receive the following error message:
    Run-time error '5':
    Invalid procedure call or argument
  8. To restore the original menu bar to the screen, type the following line in the Immediate window, and then press ENTER:
    CommandBars(strCurrentMenuName).Visible = True
    						
    Note that the original menu bar reappears, and your custom menu bar disappears.

↑ Back to the top


References

For more information about menu bars, click Microsoft Access Help on the Help menu, type Read about toolbars, menu bars, and shortcut menus in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the Protection property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type protection property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about creating command bars in code, please see the following article in the Microsoft Knowledge Base:
209974� ACC2000: How to Create Command Bars by Using Visual Basic Code

↑ Back to the top


Keywords: KB207157, kbprb, kbui

↑ Back to the top

Article Info
Article ID : 207157
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 429