Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Thanked 0 Times in 0 Posts

    Invisible toolbars (Access 2000)

    With my command DoCmd.ShowToolbar "Toolbar1", acToolbarYes i make my toolbar Toolbar1 visible.I want at the same time make all other toolbars on the screen invisible,regardless how they are called.Sometimes i have
    different toolbars shown and i am interested in a command that does not refer toa specific toolbar, but makes all the toolbats on the screeninvisible.Is it possible ?

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Arlington, Virginia, USA
    Thanked 3 Times in 3 Posts

    Re: Invisible toolbars (Access 2000)

    Attached is example of a VBA procedure that will hide all visible toolbars, with an optional parameter that allows you to specify an "exception" (toolbar or menu to keep visible). There's a second optional parameter that allows you to hide the main Menu Bar as well (not normally recommended). Sample code:

    <code>Public Sub HideAllToolbars(Optional ByRef strToolbar As String = "", _</code>
    <code> Optional ByRef HideMenu As Boolean = False)</code>

    <code> On Error GoTo Err_Handler</code>

    <code> Dim strMsg As String</code>
    <code> Dim cbr As Office.CommandBar 'ref required to MS Office Object Library</code>

    <code> ' strToolbar (optional) = name of Toolbar to keep visible, leave blank to hide all -</code>
    <code> ' default value if missing is empty string, so should not be possible to match any other visible toolbar</code>
    <code> ' HideMenu (optional) = set to True to hide app main menu bar (normally would want False)</code>

    <code> For Each cbr In Application.CommandBars</code>
    <code> If cbr.Type <> msoBarTypeMenuBar Then</code>
    <code> If cbr.Visible = True Then</code>
    <code> If cbr.Name <> strToolbar Then</code>
    <code> cbr.Visible = False</code>
    <code> End If</code>
    <code> End If</code>
    <code> Else 'Menu bar</code>
    <code> ' Exclude built-in Menu Bar (Error No -2147467259: Method 'Visible' of object 'CommandBar' failed)</code>
    <code> ' Can set Visible to True if hidden, but cannot set to False if visible</code>
    <code> If HideMenu = True Then</code>
    <code> If cbr.Name <> strToolbar Then</code>
    <code> ' the ShowToolbar command allows you to hide Menu:</code>
    <code> DoCmd.ShowToolbar cbr.Name, acToolbarNo</code>
    <code> End If</code>
    <code> End If</code>
    <code> End If</code>
    <code> Next cbr</code>

    <code> Set cbr = Nothing</code>
    <code> Exit Sub</code>
    <code> Select Case Err.Number</code>
    <code> Case 0</code>
    <code> Resume Next</code>
    <code> Case Else</code>
    <code> strMsg = "Error No " & Err.Number & ": " & Err.Description</code>
    <code> MsgBox strMsg, vbExclamation, "HideAllToolbars Sub - Unexpected Error"</code>
    <code> Resume Exit_Proc</code>
    <code> End Select</code>

    <code>End Sub</code>

    Example of use - hide ALL command bars (both menus and toolbars):

    <code>HideAllToolbars ,True</code>

    Hide all toolbars, except toolbar named Toolbar1 (keep main menu visible):

    <code>HideAllToolbars "Toolbar1"</code>

    Hide all toolbars and menus, except toolbar named Toolbar1:

    <code>HideAllToolbars "Toolbar1", True</code>

    Hide all toolbars and menus, except custom menu named Menu1:

    <code>HideAllToolbars "Menu1", True</code>

    Code requires set reference to Office X.0 Object Library. Worked OK in Access 2K. Note comments in reference to hiding the main Menu Bar. If using custom menus and toolbars in your application, I'd recommend use the Access Startup options to disable built-in toolbars and shortcut menus, and toolbar customization, and design custom application menu bar, toolbars, and shortcut (popup) menus to replace the built-in ones. All forms and reports should have their own toolbar and/or shortcut menu specified (can design a "generic" form or report toolbar for all forms/reports). This approach would result in better protection for database and would tend to obviate the need to run procedures like the example above.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts