Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Indianapolis, IN, USA

    Unanswered: Hiding and Unhiding the Nav Pane

    I’m using Access 2007. I think I have solved my problem, but I’d like to pass on some information that might be useful to others. I got the idea and part of the code from a Microsoft Access Help item with a title of “Hide database window in Access 2010.” One of the responses contains the code for a subroutine to hide and unhide the navigation pane. I tried using the author’s code but had problems with selecting an item in the nav pane. Probably nothing wrong with the code, but I didn’t understand it and it didn’t work for me. So I created a dummy table, appropriately called, “tblDummy.” I also had problems trying to unhide the nav pane and discovered that what worked was setting the focus to the form that was being used before the subroutine was called.
    IF ANYONE WOULD LIKE TO COMMENT ON THIS, I WOULD MUCH APPRECIATE IT. I’m not sure why the subroutine DisplayNavPane works in the exit routine and unhides the Nav Pane.

    The subroutine after my alterations:

    Public Sub DisplayNavPane(IsVisible As Boolean)
    ' Copied from a Access Help item that was an article from a MS Access Forums site.
    ‘ It contained "7/29/2009 DLT" as a note.
    ' I have made revisions
    On Error GoTo Err_DisplayNavPane
    ' Select an object in the Nav Pane
    DoCmd.SelectObject acTable, "tblDummy", True
    ' If the Nav Pane is visible then hide it.
    If IsVisible = False Then
    DoCmd****nCommand acCmdWindowHide
    End If
    Exit Sub
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_DisplayNavPane
    End Sub

    The code on the Load Event of my menu form, “frmMenu”:

    Private Sub Form_Load()
    On Error GoTo Err_Form_Load
    ' Hide the Nav Pane
    DisplayNavPane False
    Exit Sub
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Load
    End Sub

    The code on cmdExit button’s Click Event on my menu form, “frmMenu”:

    Private Sub cmdExit_Click()
    On Error GoTo Err_cmdExit_Click
    DisplayNavPane True
    ' Close this form
    Exit Sub
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_cmdExit_Click
    End Sub

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 15
    There's not a lot to comment, though yours is a smart idea.

    You can classify the methods of the DoCmd object in 3 categories:

    - Those needing an argument that specifies the object of the action (e.g. Docmd.OpenForm <FormName>: You need to specify the name of the form you want to open).

    - Those accepting (among possibly others) an optional argument that specifies the object of the action (e.g. DoCmd.Close [AcForm], [<FormName>]: AcForm and <FormName> are optional). Without this or these arguments the action is performed on the currently active (or sometimes default) object (e.g. DoCmd.Close closes the currently active object).

    - Those that do not accept any arguments, at least no argument that specifies the object of the action. The RunCommand method, that replaces the old DoMenuItem is one of these. The problem here is that an error occurs if the context is not appropriate when you call them. Note that this is logical as these commands are related to menu actions, and some menu options can be disabled in a given context.

    Selecting an object into the Navigation Pane activates this one and makes it the active window. This allows a call to the RunCommand acCmdWindowHide method without risking an error.

    Very clever indeed!
    Have a nice day!

  3. #3
    Join Date
    Jan 2012
    Try this:

    Sub ShowNavPane(f As Boolean)

    DoCmd.SelectObject acTable, , True

    If Not f Then DoCmd.RunCommand acCmdWindowHide

    End Sub

Posting Permissions

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