Solved Minimize Ribbon, not Menu Bar? How to Replicate the Shortcut Menu Command (1 Viewer)

riktek

Member
Local time
Today, 00:11
Joined
Dec 15, 2023
Messages
33
This is well and extensively discussed elsewhere but nevertheless all of the posted "solutions" fail and I am unable to programmatically minimize the ribbon but not the menu bar, as one can do by selecting the Menu Bar context menu's "Minimize the Ribbon" item (or pressing Ctrl + F1).

To be clear:
- Minimizing differs from hiding.
- At least two elements are involved, the Menu Bar and the Ribbon, which themselves are CommandBar objects and together may be elements of another CommandBar object, perhaps carrying a fourth element name, "Toolbar," which is undefined.

What I have observed is:
- By right clicking on the Menu Bar (but not the Ribbon), one can get a context / shortcut menu including a "Minimize the Ribbon" item, which, when selected, minimizes the ribbon but not the Menu Bar. This is the behavior I am attempting to replicate in code.
-
Code:
-    DoCmd.ShowToolbar, "Ribbon", acToolBarNo
hides (not minimizes) both the Menu Bar and the Ribbon, and with no prospect of restoring the ribbon. I imagine this sets the Visible property of all CommandBar objects to False hides (not minimizes) both the Menu Bar and the Ribbon, and with no prospect of restoring the ribbon. I imagine this sets the Visible property of all CommandBar objects to False.
-
Code:
-  CommandBars.ExecuteMso "MinimizeRibbon"
either fails or, if conditioned on some but not all values of CommandBar.Height, either fails or throws Error 5, "Invalid procedure call or argument"

ControlBars.Count is 199 but, quite oddly, attempts to iterate ControlBars.Item and ControlBar.Controls.Item with a For statement throw Error 9, "Subscript out of range" starting with both zero and 1.

Inspecting discrete ControlBar objects seems to reveal that neither has a "MinimizeRibbon" control.
Code:
CommandBars.GetPressedMso("MinimizeRibbon")
and
Code:
CommandBars.GetVisibleMso("MinimizeRibbon")
both return an error. This would seem to explain the failure of
Code:
CommandBars.ExecuteMso "MinimizeRibbon"
, at least when it isn't erroring, because it effectively just clicks the specified control.

Also, no obvious acCommand or acSysCmd constant exists for this action - many are undocumented, of course, but I haven't yet uncovered this one by Google or hack. I'm not aware of any means of getting this value from a menu or its items.

So, the question is whether, and how, one can programmatically minimize the ribbon and not the Menu Bar, as one can do by selecting the "Minimize the Ribbon" item in the Menu Bar's shortcut / context menu (or pressing Ctrl + F1). Many thanks for any constructive advice.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:11
Joined
May 7, 2009
Messages
19,246
what "menu bar" are you talking here? can you post a screenshot?


ribbon.png


so, on the image i think what you are referring as "menu bar" are those on the Red rectangle, and the "ribbon" are those on the blue rectangle?
well, they are both member of the Ribbon. the one on the Red, are the Tabs and what on the blue are the Controls.

there is a command that toggle to minimize the "ribbon" (controls) and only leave the Tabs (menu bar?).

Code:
CommandBars.ExecuteMso "MinimizeRibbon"

which, you already mentione.d
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 08:11
Joined
Jan 14, 2017
Messages
18,261
The code below allows you to show/hide/minimize/maximize the ribbon. Place in a standard module e.g. modRibbon

Code:
Public Function HideRibbon()
    'could run at startup using Autoexec
    'however this also hides the QAT which makes printing reports tricky
     DoCmd.ShowToolbar "Ribbon", acToolbarNo
   '  DoCmd.ShowToolbar "PrintReport", acToolbarYes
End Function

Public Function ShowRibbon()
    'use when opening a report to display print preview ribbon
     DoCmd.ShowToolbar "Ribbon", acToolbarYes
End Function

Public Function ToggleRibbonState()

'hide ribbon if visible & vice versa
    CommandBars.ExecuteMso "MinimizeRibbon"
End Function

Public Function IsRibbonMinimized() As Boolean
    'Result: 0=normal (maximized), -1=autohide (minimized)

    IsRibbonMinimized = (CommandBars("Ribbon").Controls(1).Height < 100)
   ' Debug.Print IsRibbonMinimized
End Function
 

riktek

Member
Local time
Today, 00:11
Joined
Dec 15, 2023
Messages
33
what "menu bar" are you talking here? can you post a screenshot?


View attachment 112985

so, on the image i think what you are referring as "menu bar" are those on the Red rectangle, and the "ribbon" are those on the blue rectangle?
well, they are both member of the Ribbon. the one on the Red, are the Tabs and what on the blue are the Controls.

there is a command that toggle to minimize the "ribbon" (controls) and only leave the Tabs (menu bar?).

Code:
CommandBars.ExecuteMso "MinimizeRibbon"

which, you already mentione.d
Thanks for getting back. The Menu Bar is the menu bar, the part in the red that has menu items. In code, its name is "Menu Bar", at least according to the values the CommandBars object returns

The Ribbon is the Ribbon, the part in blue with the iconified controls. In code, its name is "Ribbon", at least according to the values the CommandBars object returns

They are distinct members of the CommandBars collection, according to it. I understand that they are both members of a third object but which, its name, or index, isn't clear.

Sadly, the command you describe is the same one I described in my initial post as failing because the command effectively clicks the ribbon control having the quoted name, and that ribbon control seems not to exist. It's difficult to discern because one can't iterate through CommandBar.Controls without error but direct references fail.

More to the point, this and the DoCmd command I mentioned clearly aren't the command that the GUI is executing via the Menu Bar's shortcut menu, or via Ctrl + F1. The question, really, is how to do that command in code (short of SendKeys).
 
Last edited:

riktek

Member
Local time
Today, 00:11
Joined
Dec 15, 2023
Messages
33
The code below allows you to show/hide/minimize/maximize the ribbon. Place in a standard module e.g. modRibbon

Code:
Public Function HideRibbon()
    'could run at startup using Autoexec
    'however this also hides the QAT which makes printing reports tricky
     DoCmd.ShowToolbar "Ribbon", acToolbarNo
   '  DoCmd.ShowToolbar "PrintReport", acToolbarYes
End Function

Public Function ShowRibbon()
    'use when opening a report to display print preview ribbon
     DoCmd.ShowToolbar "Ribbon", acToolbarYes
End Function

Public Function ToggleRibbonState()

'hide ribbon if visible & vice versa
    CommandBars.ExecuteMso "MinimizeRibbon"
End Function

Public Function IsRibbonMinimized() As Boolean
    'Result: 0=normal (maximized), -1=autohide (minimized)

    IsRibbonMinimized = (CommandBars("Ribbon").Controls(1).Height < 100)
   ' Debug.Print IsRibbonMinimized
End Function
Big thanks for getting back.

As noted, I've tried both commands and both have failed.

The DoCmd command hides everything, including the QAT and even the Application Title. It's the nuclear option for wiping half the GUI and nothing less. Clearly not an option.

The CommandBars method fails because it effectively clicks the CommandBar control named in quotes, and that control appears not to exist. It's difficult to discern because one can't iterate CommandBar.Controls items without error but attempts to specify it directly (CommandBar.Controls("Ribbon")) yield no results.

As noted elsewhere, these two clearly aren't the command the GUI executes via the Menu Bar's shortcut menu or by pressing Ctrl + F1. The question, really, is how to execute that command in code, short of a SendKeys call.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:11
Joined
May 7, 2009
Messages
19,246
Sadly, the command you describe is the same one I described in my initial post as failing because the command
you want to Minimize the ribbon, am I correct?

 

isladogs

MVP / VIP
Local time
Today, 08:11
Joined
Jan 14, 2017
Messages
18,261
There seems to be some lack of clarity about what you mean.
If you want to minimize a maximized ribbon (or vice versa), the code line CommandBars.ExecuteMso "MinimizeRibbon" does EXACTLY the same thing as Ctrl+F1. It toggles between the two states (unless the ribbon has been hidden)

F11 maximizes / minimizes the navigation pane ...NOT the ribbon

Just to check which version of Access are you using? I ask as not all ribbon code works in version 2007
 

riktek

Member
Local time
Today, 00:11
Joined
Dec 15, 2023
Messages
33
There seems to be some lack of clarity about what you mean.
If you want to minimize a maximized ribbon (or vice versa), the code line CommandBars.ExecuteMso "MinimizeRibbon" does EXACTLY the same thing as Ctrl+F1. It toggles between the two states (unless the ribbon has been hidden)

F11 maximizes / minimizes the navigation pane ...NOT the ribbon

Just to check which version of Access are you using? I ask as not all ribbon code works in version 2007
You're right about F11, my mistake. Ctrl + F1 is what does the trick. I'll edit my original post presently.

I am actually working on 2007 for present purposes. Its ribbon implementation not being ready for prime time as you say explains much, not only the fact that the ExecuteMso method actually does NOT do the same thing as Ctrl+F1 (at least in this context), but perhaps also the inability to iterate the items of any of the relevant objects' collections.

Quite helpful, and thanks. It looks as if the SendKeys approach unfortunately is the only avenue in this context.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 08:11
Joined
Jan 14, 2017
Messages
18,261
Its a pity you didn't mention Access 2007 in the first post. It would have saved us all a lot of time!
If you look at my article: Manage Taskbar/Nav Pane/Ribbon (isladogs.co.uk), you will see I stated that the ToggleRibbonState code has no effect in A2007. IIRC, you will have to use SendKeys to do this unless you upgrade to a newer version (A2010 onwards)

On the other hand, as you also mentioned the navigation pane, there is code using command bars that worked in that version but not in any ssubsequent version: Navigation pane search bar code (isladogs.co.uk)
 

riktek

Member
Local time
Today, 00:11
Joined
Dec 15, 2023
Messages
33
Its a pity you didn't mention Access 2007 in the first post. It would have saved us all a lot of time!
If you look at my article: Manage Taskbar/Nav Pane/Ribbon (isladogs.co.uk), you will see I stated that the ToggleRibbonState code has no effect in A2007. IIRC, you will have to use SendKeys to do this unless you upgrade to a newer version (A2010 onwards)

On the other hand, as you also mentioned the navigation pane, there is code using command bars that worked in that version but not in any ssubsequent version: Navigation pane search bar code (isladogs.co.uk)
Colin, you're a font of knowledge. More than I can bite off on this instant but I've just bookmarked those of your pages I hadn't already. Among other things, the NavPane code addresses an item on my development plan.

I've already settled on the SendKeys approach for A2007 contexts and had just roughed out pseudocode for a procedure that runs the better alternative depending on version. If it works, it will complement yours a bit and I'll send it along.

I am guilty on occasion of treating the code base 2007-on to be immutable (but for bitness) although I do know better. That something should work in A2007 but not subsequently is interesting.

Cheers
 

isladogs

MVP / VIP
Local time
Today, 08:11
Joined
Jan 14, 2017
Messages
18,261
Thanks.
A2007 is an oddity in terms of behaviour in many ways so its always important to mention when you are using it.

However, its VERY unusual for code to work in A2007 but not in later versions.
I reported that example to the Access team last summer and I expect it will eventually be fixed...but its not top priority
 

Users who are viewing this thread

Top Bottom