CommandBars (1 Viewer)

Freshman

Registered User.
Local time
Today, 04:28
Joined
May 21, 2010
Messages
437
Hi all,

I found some code which is suppose to display all menu items:
Code:
Dim CB As Commandbar, crl As CommandBarControl
Set CB = CommandBars("Menu Bar")
For Each crl In CB.Controls
   Msgbox crl.Caption
Next
However the code displays the default menu items and not my custom menu which I defined in a Marco as "TopMenu" (also in Access Options).
The code fails if I swap "Menu Bar" with "TopMenu"

Q1: How to I define my custom menu bar?
Q2: I need to refrence "Microsoft Office 12.0 Object Lib" for this to work. How do I do the same using Late binding

Thanks
Pierre
 

ByteMyzer

AWF VIP
Local time
Yesterday, 18:28
Joined
May 3, 2004
Messages
1,409
Q1 Answer: If you use a Macro for your menu, I do not believe that it appears in the CommandBars collection.
Q2 Answer: If you make the following change in your code, you do not require the reference to the Microsoft Office 12.0 Object Library:
Code:
[COLOR="Navy"]Dim[/COLOR] CB [COLOR="navy"]As Object[/COLOR], crl [COLOR="navy"]As Object[/COLOR]
 

Freshman

Registered User.
Local time
Today, 04:28
Joined
May 21, 2010
Messages
437
@ByteMyzer - thanks for the advice. I have way too many menu items to convert them all to vba. Will take me ages. The one item I wanted to grey out for some Users I will block via code before opening the target query

Thanks
 

Users who are viewing this thread

Top Bottom