locked
VBA / Navigation Pane RRS feed

  • Question

  • Hi,

    Two questions about using VBA to manipulate the Navigation Pane in Access 2007/2010:

    1. Is it possible through VBA to simply close the Navigation Pane without actually hiding it?

    2. I've come across code to hide the Navigation Pane (if there's no way to just close it),
    but some people seem to be suggesting just the command "
    DoCmd.RunCommand acCmdWindowHide", while other sources seem to suggest that this has to be prefaced with "DoCmd.SelectObject acTable, “YourTable”, True" -- with "YourTable" being either an actual table or not an actual table. That part wasn't clear, either.

    Could someone clarify this, please?

    Thank you.
    Mark

     

    Thursday, November 4, 2010 1:39 PM

Answers

  • Hello Mdavisfps,

    Welcome to MSDN forum, and I am very glad to help with you.

    After reading your post, I understand that you want to close or hide Navigation Pane by VBA. If I have misunderstood you, please let me know.

                Based on my analysis, it is not possible to close it programmatically, but you can hide it programmatically.

                ‘ hide

                Private Sub Command1_Click()

    DoCmd.NavigateTo "acNavigationCategoryObjectType"

    DoCmd.RunCommand acCmdWindowHide

    End Sub

    ‘unhide

    Private Sub Command2_Click()

    DoCmd.SelectObject acTable, , True

    End Sub

    In addition, you can close Navigation Pane manually, and you can take a look at this article:

    http://office.microsoft.com/en-us/access-help/close-and-reopen-the-navigation-pane-and-the-objects-in-the-pane-HA001213878.aspx#BM2

                I hope this can help you and feel free to follow up after trying the code.

    Best Regards,

    Bruce Song


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by mdavisfps Monday, November 8, 2010 5:10 PM
    Monday, November 8, 2010 3:21 AM
  • Because the RunCommand acWindowHide action does not have a way to specify which window to hide, you have to do something to indicate the window.  Selecting a table is one way, but actually you only have to select a tab in the window as DoCmd SelectObject acTable, , True does (note the table name is not specified).  Any tab will dom but the Table tab is the one everybosy uses so using it will not cause anyone to stop and ponder why you used something else.

    The NavigateTo action is a new way to select the Nav Pane and in time will probably become the commonly understood way to indicate the window to hide.

    • Marked as answer by mdavisfps Monday, November 8, 2010 5:09 PM
    Monday, November 8, 2010 3:46 AM
  • You'll have no problems with the codes given by others here.

    The problem as they point out, you need to select the object in the navigation pane(pain). Else if you don't, the object in focus would be hidden! Not what you intend to do.

    Another problem would occur is a new database without any newly created objects. Example, if you created a form and created a code to hide the navigation pane and did not save the form. You run the code in the form. The code will hide the form instead of the navigation pane.

    Why?

    Because the navigation pane has no object in focus only the form is in focus. And as the form is not saved, there no object selected in the nav pane. That's why you need to select the object.

    Note: Default hidden objects are not discussed here.

    • Marked as answer by mdavisfps Monday, November 8, 2010 5:10 PM
    Monday, November 8, 2010 4:57 AM

All replies

  • Hello Mdavisfps,

    Welcome to MSDN forum, and I am very glad to help with you.

    After reading your post, I understand that you want to close or hide Navigation Pane by VBA. If I have misunderstood you, please let me know.

                Based on my analysis, it is not possible to close it programmatically, but you can hide it programmatically.

                ‘ hide

                Private Sub Command1_Click()

    DoCmd.NavigateTo "acNavigationCategoryObjectType"

    DoCmd.RunCommand acCmdWindowHide

    End Sub

    ‘unhide

    Private Sub Command2_Click()

    DoCmd.SelectObject acTable, , True

    End Sub

    In addition, you can close Navigation Pane manually, and you can take a look at this article:

    http://office.microsoft.com/en-us/access-help/close-and-reopen-the-navigation-pane-and-the-objects-in-the-pane-HA001213878.aspx#BM2

                I hope this can help you and feel free to follow up after trying the code.

    Best Regards,

    Bruce Song


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by mdavisfps Monday, November 8, 2010 5:10 PM
    Monday, November 8, 2010 3:21 AM
  • Because the RunCommand acWindowHide action does not have a way to specify which window to hide, you have to do something to indicate the window.  Selecting a table is one way, but actually you only have to select a tab in the window as DoCmd SelectObject acTable, , True does (note the table name is not specified).  Any tab will dom but the Table tab is the one everybosy uses so using it will not cause anyone to stop and ponder why you used something else.

    The NavigateTo action is a new way to select the Nav Pane and in time will probably become the commonly understood way to indicate the window to hide.

    • Marked as answer by mdavisfps Monday, November 8, 2010 5:09 PM
    Monday, November 8, 2010 3:46 AM
  • You'll have no problems with the codes given by others here.

    The problem as they point out, you need to select the object in the navigation pane(pain). Else if you don't, the object in focus would be hidden! Not what you intend to do.

    Another problem would occur is a new database without any newly created objects. Example, if you created a form and created a code to hide the navigation pane and did not save the form. You run the code in the form. The code will hide the form instead of the navigation pane.

    Why?

    Because the navigation pane has no object in focus only the form is in focus. And as the form is not saved, there no object selected in the nav pane. That's why you need to select the object.

    Note: Default hidden objects are not discussed here.

    • Marked as answer by mdavisfps Monday, November 8, 2010 5:10 PM
    Monday, November 8, 2010 4:57 AM
  • Thanks All,

    I use an autoexec macro to open my switchboard form. In the Open event of that form I placed the following:

    If SysCmd(acSysCmdAccessVer) > 11 Then
    DoCmd.RunCommand acCmdWindowHide
    Else
    'earlier version so do nothing
    End If

    -- I still do development in Access 97, then convert on a 2002 box and then distribute to 2002-2007-2010 users.

    -- The above code seems to work fine when it reaches the 2007 users. Haven't had a chance to try it yet with 2010.

    -- I had come across other suggestions which seemed to use a similar approach ... just the DoCmd.RunCommand acCmdWindowHide without specifically referencing the Navigation Pane (AccessVandal, I agree with the alternate spelling). I thank you all, however, for the other comments and insights and I plan on considering them further.

    Thank you,
    Mark

    Monday, November 8, 2010 1:37 PM
  • Bruce, I am glad that I found your answer; however, when I first implemented I was dismayed that it did not seem to work for me. After much frustration and experimentation I came back to it and thought that my issue might be that I made a modal popup to let the user select the backend file that they wish to use.

    I thought I would share my modified code in case anyone else runs into this issue

    Thanks,

    Chris

     

    'Funtion to hide the navigation pane
    Function HideNavigationPane(ByRef CalledFromForm As Form)
    
     If (CalledFromForm.Modal = True) Then      'If the form is set to modal
     
      CalledFromForm.Modal = False            'Disable modal
      
      DoCmd.NavigateTo _
       "acNavigationCategoryObjectType"        'Select Navigation Pane
        
      DoCmd.RunCommand acCmdWindowHide    'Hide selected
      
      CalledFromForm.Modal = True            'Enable modal
      
     Else                                'Else not modal
     
      DoCmd.NavigateTo _
       "acNavigationCategoryObjectType"        'Select Navigation Pane
        
      DoCmd.RunCommand acCmdWindowHide     'Hide selected
      
     End If
    
    End Function


     

     

     


    • Edited by StreckerCM Tuesday, June 28, 2011 7:51 PM adjust formatting
    Tuesday, June 28, 2011 7:49 PM
  • Can you assist me with your code?  I have created a Module with this function and tried to call it on load using

    DoCmd.runcode HideNavigationPane2(me.form)

    The only Difference is I have choosen accmdwindowunhide.  I get an error saying action is not available now.  Any ideas?

     

    Function HideNavigationPane2(ByRef CalledFromForm As Form)

     If (CalledFromForm.Modal = True) Then      'If the form is set to modal
     
      CalledFromForm.Modal = False            'Disable modal
     
      DoCmd.NavigateTo _
       "acNavigationCategoryObjectType"        'Select Navigation Pane
       
      DoCmd.RunCommand acCmdWindowUnhide    'Hide selected
     
      CalledFromForm.Modal = True            'Enable modal
     
     Else                                'Else not modal
     
      DoCmd.NavigateTo _
       "acNavigationCategoryObjectType"        'Select Navigation Pane
       
      DoCmd.RunCommand acCmdWindowUnhide     'Hide selected
     
     End If

    End Function

    Tuesday, August 2, 2011 8:18 PM
  • Never Mind.  I the Code fromt eh top works fine.

     

    DoCmd.SelectObject acTable, , True

    Tuesday, August 2, 2011 8:19 PM
  • Following the thread on hiding the toolbar and navigation pane, I have come across the following problem:

    I have a form which acts as a main menu and opens at start up.  Using the code suggested in the thread it successfully hides both:

        DoCmd.RunCommand acCmdWindowHide
        DoCmd.ShowToolbar "Ribbon", acToolbarNo

    I then have a button on this form which allows me to toggle on and toggle off the toolbar and navigation pane:

    Private Sub cmdShowNavigationAndToolbar_Click()
        If Me.cmdShowNavigationAndToolbar.Caption = "&Show Navigation Pane and Toolbar" Then
            DoCmd.NavigateTo "acNavigationCategoryObjectType"
            DoCmd.SelectObject acForm, , True
            DoCmd.ShowToolbar "Ribbon", acToolbarYes
            Me.cmdShowNavigationAndToolbar.Caption = "&Hide Navigation Pane and Toolbar"
        Else
            DoCmd.RunCommand acCmdWindowHide
            Me.Visible = True
            DoCmd.ShowToolbar "Ribbon", acToolbarNo
            Me.cmdShowNavigationAndToolbar.Caption = "&Show Navigation Pane and Toolbar"
        End If
    End Sub

    This shows both toolbar and navigation pane, but when I click it again to run the code to hide them for a second time the navigation pane stays unhidden.  Only when I exit Access and come in again does it work, but again, only for the first time and not subsequently.  Incidentally the 'me.visible=true' had to be inserted otherwise when I hide the navigation pane the form hides as well.

    Sunday, December 18, 2011 11:33 AM
  • In case anyone needs it, you can just close the navigation pane

    DoCmd.NavigateTo "acNavigationCategoryObjectType"
    DoCmd.Minimize

    Tuesday, May 15, 2012 6:50 PM
  • Bruce,

    Thanks. Pure Genius!

    Jeff


    Jeff Lemon

    • Proposed as answer by Jeff Lemon Wednesday, June 20, 2012 12:56 AM
    Wednesday, June 20, 2012 12:56 AM
  • I am so frustrated by this!! THIS CODE IS UNRELIABLE! IF all of the "sections" of the nave pane have been minimized (using the little v ) then the object will NOT be selected and whatever window has the focus will be hidden!

    So the question is how do you force one of the sections open so it can be selected.


    Kim

    Wednesday, August 1, 2012 12:01 AM
  • I see no one has responded to my post. This is clearly an MS bug that should be fixed. I have users that are ALLOWED access to the nave pane and users who are not. I need to know if the nav pane is open and if it is leave it alone. Then when I link a table (and it opens on its own - which is a BUG which MS should address) I can decide whether to close the nav pane or not.


    Kim

    Thursday, August 22, 2013 9:20 PM
  • Thanks a lot Sir. I was searching for the same and it solved my problem. Also is there any method / Function to hide menu bar also??

    Monday, November 25, 2013 9:30 AM
  • amusing that this does not work for me and errors with improper us of "me."  having scowered the internet I can see that there is no solution to this problem.  I also thing that all responses are not really aware of the problem.  Once F11 is pushed, the Navigation Pane stays.  Developers want to continually monitor for this even and close it.
    Monday, December 30, 2013 7:30 PM
  • this could have been given a specific coding and not this generic blurb.  People are lost enough without having to now look up what "acNavigationCategoryObjectType" code they need.  interesting that 'minimize' now fills in for 'hide'.
    Monday, December 30, 2013 7:33 PM
  • Chris, I'm using Access 2007 and using this exact piece of code does the exact opposite.  When I press F11, the Navigation Pane that isn't visible is actually displayed but the form is hidden.
    Monday, February 17, 2014 8:05 PM
  • In case anyone needs it, you can just close the navigation pane

    DoCmd.NavigateTo "acNavigationCategoryObjectType"
    DoCmd.Minimize

    In Access 2007, this code doesn't appear to have any effect.  A Navigation Pane that isn't visible will be made visible via the F11 key.  I just stepped through the code :-(
    Monday, February 17, 2014 8:15 PM
  • I am so frustrated by this!! THIS CODE IS UNRELIABLE! IF all of the "sections" of the nave pane have been minimized (using the little v ) then the object will NOT be selected and whatever window has the focus will be hidden!

    So the question is how do you force one of the sections open so it can be selected.


    Kim

    It really doesn't matter if they are expanded or not.  Even when mine are, the "acCmdWindowHide" code still hides the form and disregards the Navigation Pane.
    • Proposed as answer by Javiermc Friday, September 26, 2014 9:24 AM
    • Unproposed as answer by Javiermc Friday, September 26, 2014 9:24 AM
    Monday, February 17, 2014 8:33 PM
  • Just in case someone coul find this helpfull, in one of my applications, "NavigateTo" + "acCmdWindowHide" didn't work in some cases.

    I realized that the problem was the visibility of some forms from where I wanted to hide the exploration pane.

    So I modified the Sub in this way (sub and variable names ar in spanish, so i am).

    Sub OcultaPanelDeNavegacion()
       
        Dim Formulario As Form
       
        On Error Resume Next
       
        Set Formulario = Screen.ActiveForm
       
        Formulario.Visible = False
       
        DoCmd.NavigateTo "acNavigationCategoryObjectType"

        DoCmd.RunCommand acCmdWindowHide

        Formulario.Visible = True
       
        On Error GoTo 0
       
        Set Formulario = Nothing
       
    End Sub

    There is a little blink when the Sub runs, but, at lest in my computer, is very short.

    On Error is the lazy way to avoid an error if the caller of the Sub is not a form, of course there are better ways to solve this.

    I've been testing it in my application and, so far, it works always.


    • Edited by Javiermc Friday, September 26, 2014 9:38 AM
    Friday, September 26, 2014 9:36 AM
  • Kim

    As far as I can see you can avoid this if you use a specific ObjectType view for example:

    DoCmd.NavigateTo "acNavigationCategoryObjectType", "acNavigationGroupForms"
    DoCmd.RunCommand acCmdWindowHide
    assuming that your database always has at least one previously saved Form object.

    Even if the current view of the Pane is 'All Access Objects' with all the individual object type sections collapsed, when an individual ObjectType view is selected (manually or by code), this can't be collapsed so if there is at least one object of that type to be displayed, the Pane can always receive focus.

    HTH


    Jon Lewis

    • Proposed as answer by HH1970 Thursday, June 7, 2018 1:28 PM
    Wednesday, October 22, 2014 10:41 AM
  • I know this is an old one but... I needed it and developed this as an alternative to hiding it. I like the close/open option better.  To all the answers below: Thanks you were a help.

    I was able to Open and Close the Navigation Pane using the SendKeys command.  The line of code I used was:

        SendKeys ("{F11}")

    This toggles the Navigation Pane Open and Closed.  It would be nice to check the state then run the code depending on what you want the button? to do.

    Peace, Andy

    Wednesday, April 1, 2015 3:27 PM
  • Hi, try this:

    Public Function NavigationPaneHide()
    On Error Resume Next
      DoCmd.SelectObject acTable, "Personal", True
      DoCmd.RunCommand acCmdWindowHide
    End Function

    Public Function NavigationPaneShow()
    On Error Resume Next
      DoCmd.SelectObject acTable, "Personal", True
    End Function

    Friday, December 21, 2018 8:19 AM
  • If you want to have the Navigation Pane minimized on opening the database, run the following function in the AutoExec macro

    Function SetMyOptions()

    'Open Nav Pane collapsed
        CurrentDb.Properties("Startupshowdbwindow") = False
        SendKeys ("{F11}")
        SendKeys ("{F11}")
      
    End Function

    For what it's worth, I also use this function to set up several other options like: 

    'set default path to current Folder
        Application.SetOption "default database directory", CurrentProject.Path

    'minimize Ribbon
        CommandBars.ExecuteMso "MinimizeRibbon"
        
    'maximize Access
        Application.SetOption "maximized", True

    'turn off Compact On Close
        Application.SetOption "Auto compact", False

    'turn off Name Auto Correct
        Application.SetOption "perform name autocorrect", False

    'disable Layout View for forms and reports
        Application.SetOption "DesignwithData", False

    Friday, February 1, 2019 9:28 PM