Solved Unhide Navigation Pane on AutoExec (1 Viewer)

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
Based on a table called "Setting", containing fields "Menu" and "NavPane" as boolean, I want to run an AutoExec macro to show or hide the Nenu and Navigation Pane,
I am able to work with the Menu and also to Hide the navigation Pane
Anything I tried so far to Unhide the Nav Pane (value set tu true in Settings Table) runs into an error

Any ideea how can i do suche an "Unhide" operation?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
Can you use VBA executed by the macro?
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
That's waht I am trying
I created a function in a module and ttryed to Run it as Code in a Macro
Fails to unhide

Code:
Public Function ToggleMenuAndNavPane() As Boolean

    Dim showMenu As Boolean
    Dim showNavPane As Boolean

    showMenu = DLookup("Menu", "Settings")
    showNavPane = DLookup("NavPane", "Settings")
    
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowHide
    
    If Not showMenu Then
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
    Else
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
    End If
    
    On Error Resume Next ' Trap error and continue execution
    
    If Not showNavPane Then
        DoCmd.RunCommand 1303 ' Hide Navigation Pane
    Else
        DoCmd.RunCommand 1302 ' Unhide Navigation Pane
    End If

    On Error GoTo 0 ' Reset error handling
    
    ToggleMenuAndNavPane = True

End Function

Code:
Option Compare Database
Option Explicit

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Boolean

Public Function ToggleMenuAndNavPane() As Boolean

    Dim showMenu As Boolean
    Dim showNavPane As Boolean

    showMenu = DLookup("Menu", "Settings")
    showNavPane = DLookup("NavPane", "Settings")
    
    DoCmd.SelectObject acTable, , True
    DoCmd.RunCommand acCmdWindowHide
    
    If Not showMenu Then
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
    Else
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
    End If
    
    If Not showNavPane Then
        ' Hide Navigation Pane using Windows API
        Dim hwndNavPane As LongPtr
        hwndNavPane = FindWindow("NetUIHWND", vbNullString)
        ShowWindow hwndNavPane, 0
    Else
        ' Show Navigation Pane using Windows API
        hwndNavPane = FindWindow("NetUIHWND", vbNullString)
        ShowWindow hwndNavPane, 5
    End If

    ToggleMenuAndNavPane = True

End Function

Both codes are failing ONLY to unhide the Nav Pane
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
Here's what I use to unhide the Nave Pane.
Code:
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
Sent from phone...
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
Here's what I use to unhide the Nave Pane.
Code:
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide
Sent from phone...
1676583911111.png

1676583940761.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
Oops, sorry. I copied the wrong code. That's what I use to "hide" the Nav Pane. To unhide, I just use the following.
Code:
DoCmd.SelectObject acTable, , True
Sent from phone...
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
This thing it drives me crazy
Really don't understand why they are not mirroring a command

Ok... Now it works from Menu = True, NavPane = True

But for Menu = false, NavPane = Flase
Menu is Hidden (thanks God) but the Navigation Pane runs into error

1676584695019.png

1676584802186.png


The crazyest thing is that I am using DoCmd.SelectObject. (asTable,,True) into a button On Click event and it works like a charm

1676584990228.png


But when it comes about the Macro... The TwiLight Zone opens
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 17:40
Joined
Sep 12, 2006
Messages
15,658
Maybe you could just sendkeys "F11".
I know it's a bit Heath Robinson, but we press F11 to open the panel.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
This thing it drives me crazy
Really don't understand why they are not mirroring a command

Ok... Now it works from Menu = True, NavPane = True

But for Menu = false, NavPane = Flase
Menu is Hidden (thanks God) but the Navigation Pane runs into error

View attachment 106497
View attachment 106498

The crazyest thing is that I am using DoCmd.SelectObject. (asTable,,True) into a button On Click event and it works like a charm

View attachment 106499

But when it comes about the Macro... The TwiLight Zone opens
Sorry to hear that. I really don't use macros.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 17:40
Joined
Sep 12, 2006
Messages
15,658
Offhand, I'm not sure what the be precise syntax syntax is to send an "F11" keystroke.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
How else can I do an AutoExec?
Off the top of my head, try having the Autoexec macro just open the startup form, you have one, right?, and then just have the form execute the VBA.

Just a thought...
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
Off the top of my head, try having the Autoexec macro just open the startup form, you have one, right?, and then just have the form execute the VBA.

Just a thought...
I was thinking on that
Not even in the Main Menu form, but in a blank form
This may work
The ideea is to prevent the user to mess with the "behind the scene" items
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
I was thinking on that
Not even in the Main Menu form, but in a blank form
This may work
The ideea is to prevent the user to mess with the "behind the scene" items
I get it. Let us know how it goes. Good luck!
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
I get it. Let us know how it goes. Good luck!
it works like this
Created a kind of Landing form, linked to settings table
All the job is done in the On_Load event
I also set a timer for 2 seconds, the closes the Landing and opens Main
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:40
Joined
Oct 29, 2018
Messages
21,474
it works like this
Created a kind of Landing form, linked to settings table
All the job is done in the On_Load event
I also set a timer for 2 seconds, the closes the Landing and opens Main
Good job! Glad to hear you got something going. Cheers!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:40
Joined
Feb 19, 2002
Messages
43,296
Since you do NOT want the user mucking about with objects, there actually is no reason to do this with code even though you can. For your purposes, when you want to develop, you open the database using the Shift bypass so you can see the navigation pain (sic)
 

Romio_1968

Member
Local time
Today, 19:40
Joined
Jan 11, 2023
Messages
126
Since you do NOT want the user mucking about with objects, there actually is no reason to do this with code even though you can. For your purposes, when you want to develop, you open the database using the Shift bypass so you can see the navigation pain (sic)
You are right, and not right.
Yes, for a user that is fluent on using Acces, it is pretty hard to set fences. Probably for that case an .accdr or even .accde is a bettrer.
Yet, for an librarian with minimal knowledge of Access, the bypass is atomic science. Usualy they are doing stuff without knowing what they are actualy doing. For that the fence must be installed.
 

Users who are viewing this thread

Top Bottom