Commandbars control turn off / on (1 Viewer)

FuzMic

DataBase Tinker
Local time
Today, 09:54
Joined
Sep 13, 2006
Messages
719
Hi guys Wow new image .. good show

My issue today is i have an toolbar eg "1Views" with an sub menu eg "1V-Sub" which itself contain few controls "SeeIt1", "SeeIt2".

My simple wish is to be able to toggle "1V-Sub".Visible between True/False when a certain state occur, thus stopping all its sub controls

I use Set cbCH = CommandBars("1Views").Controls("1V-Sub") where cbCH is defined as CommandBarControl

Since "1V-Sub" is not a control (I think), it thus throw an error. What should be right codes, Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:54
Joined
May 7, 2009
Messages
19,229
not sure, but you can delete the menu and re-create it without the sub-menu.

or if you are using Customized Ribbon, add a Global boolean variable that
getEnabled() sub can process on that ribbon control.

EDIT:

after googling, you can without deleting the cbr;

Dim cbr As Office.CommandBar
Dim cbo As CommandBarControl
Set cbr = Application.CommandBars("1Views")
Set cbo = cbr.Controls![1V-Sub]
cbo.Visible = False
 
Last edited:

FuzMic

DataBase Tinker
Local time
Today, 09:54
Joined
Sep 13, 2006
Messages
719
Thanks bro for trying. From what i know what you found is the same. Thus following also equivalent
Application.CommandBars("1Views").Controls![1V-Sub].Visible = False

I just found: only the top level control include "Menu Headings" will not give an error. If the control is below the top level referring to it will flag an error. Guys any idea about this.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:54
Joined
May 7, 2009
Messages
19,229
post a sample db.

I think what you found is a misconception.
see this demo. open Module1 and play with Sub test.
i have 2 menu deep and yet it can be disabled.
 

Attachments

  • TestCommandBars.zip
    25 KB · Views: 96
Last edited:

FuzMic

DataBase Tinker
Local time
Today, 09:54
Joined
Sep 13, 2006
Messages
719
Good follow up, good job. I want to convert to mdb to check it out.
 

FuzMic

DataBase Tinker
Local time
Today, 09:54
Joined
Sep 13, 2006
Messages
719
Brother after looking at your codes my mistakes is in the line
.. Application.CommandBars("1Views").Controls![1V-Sub].enabled = False
because 1V-Sub is at next level.
Thus i need to use your idea of 2 x CommandBarControl so i can set the lower level control by referring to the top level control.

Thank you very much for the good lesson, thread is closed. Have a good day.
 

Users who are viewing this thread

Top Bottom