Better Code To Show/Hide Ribbon + NavPane (1 Viewer)

eirman

Registered User.
Local time
Today, 11:06
Joined
Aug 16, 2013
Messages
38
I'm using this code to show and hide the ribbon & navigation pane from within a form. I'm using a regular command button as a toggle. It works fine in normal daily use, but not always, after coming out of design mode. Sometimes the form I'm designing closes and sometimes the nav pane shows and the ribbon is hidden.

Code:
Private Sub CommandHIDE_Click()
    Static IsHidden As Boolean

    If IsHidden Then
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
        DoCmd.SelectObject acTable, , True
        IsHidden = False
    Else
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
        DoCmd.NavigateTo "acNavigationCategoryObjectType"
        DoCmd.RunCommand acCmdWindowHide
        IsHidden = True
    End If
End Sub
I'm sure that there is much more robust code out there to perform this common function. All suggestion will be much appreciated.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:06
Joined
Feb 28, 2001
Messages
20,062
Actually, that's not that different from what I use, although in my case I pass in the equivalent to your "IsHidden" flag from the routine that calls this.

Why do you think it isn't robust?
 

eirman

Registered User.
Local time
Today, 11:06
Joined
Aug 16, 2013
Messages
38
Why do you think it isn't robust?

Hi DocMan, It's not an end user button. I use it for the quick viewing of a full screen form after a design or vb change. Unfortunately it doesn't always work.

I can't figure what causes the error (described in my OP) ... perhaps I should have a save all built into it.
 

Ari

Registered User.
Local time
Today, 03:06
Joined
Oct 22, 2011
Messages
134
Hi

Might work if you store the flag in the list of properties (or in a field of a table).

To create a property, run only once the following code:

Dim prpNew as Property
Set prpNew = CurrentDb.CreateProperty("isHidden", dbBoolean, 0)
CurrentDb.Properties.Append prpNew

Change your code to:

Code:
Private Sub CommandHIDE_Click()
 
    If [B]Currentdb.properties!isHidden.value[/B] Then
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
        DoCmd.SelectObject acTable, , True
        [B]Currentdb.properties!isHidden.value[/B] = False
    Else
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
        DoCmd.NavigateTo "acNavigationCategoryObjectType"
        DoCmd.RunCommand acCmdWindowHide
        [B]Currentdb.properties!isHidden.value[/B]= True
    End If
End Sub

Once you enter the mode structure, and not miss the last value IsHidden.
 

eirman

Registered User.
Local time
Today, 11:06
Joined
Aug 16, 2013
Messages
38
Thanks Ari, I've never created a property before. I'll give it a try and report back.

Could you post the code you are using Doc_Man. Thanks
 

emorris1000

Registered User.
Local time
Today, 03:06
Joined
Feb 22, 2011
Messages
125
I have some code in mine to call the functions "UserMode" and "DeveloperMode". DeveloperMode shows ribbons and all that jazz, UserMode hides it. Here's the basic code

Code:
Public Function UserMode()
    DoCmd.SelectObject acTable, "Switchboard Items", True
    DoCmd.RunCommand acCmdWindowHide
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
End Function

Code:
Public Function DeveloperMode()
If InputBox("Enter Password") = "admin" Then
    DoCmd.SelectObject acTable, "Switchboard Items", True
    DoCmd.ShowToolbar "Ribbon", acToolbarYes
Else
    MsgBox ("Password Incorrect")
End If

There's also a ghetto password in there just to stop people jumping into dev mode.

edit: looking at that code I can't remember why you have to select the switchboard items table. There's some goofy reason for that. I think you have to have an object selected for this, and I call this code when the database launches, so it has to grab a table....

Honestly though I ca't rememember why I do that.

edit2: I guess our code is pretty much the same except I don't use the boolean. You may want to just avoid using the toggle switch and have people select the specific mode themselves.
 

eirman

Registered User.
Local time
Today, 11:06
Joined
Aug 16, 2013
Messages
38
Some useful bits of code there emorris1000
Thanks
 

yosvanyisel

New member
Local time
Today, 06:06
Joined
Oct 22, 2015
Messages
1
You are the Best THANKS SO MUCH!!!!!!!!!!!!!

Hi

Might work if you store the flag in the list of properties (or in a field of a table).

To create a property, run only once the following code:

Dim prpNew as Property
Set prpNew = CurrentDb.CreateProperty("isHidden", dbBoolean, 0)
CurrentDb.Properties.Append prpNew

Change your code to:

Code:
Private Sub CommandHIDE_Click()
 
    If [B]Currentdb.properties!isHidden.value[/B] Then
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
        DoCmd.SelectObject acTable, , True
        [B]Currentdb.properties!isHidden.value[/B] = False
    Else
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
        DoCmd.NavigateTo "acNavigationCategoryObjectType"
        DoCmd.RunCommand acCmdWindowHide
        [B]Currentdb.properties!isHidden.value[/B]= True
    End If
End Sub

Once you enter the mode structure, and not miss the last value IsHidden.
 

Users who are viewing this thread

Top Bottom