Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Menu Item

Status
Not open for further replies.

Rydel

Programmer
Feb 5, 2001
376
CZ
What's the best and simplest way in VBA to insert a menu item into an existing MS Access menu (and that should happen when you open the .MDB file). Thanks in advance!





regards,
rydel n23
 
My code that does this is on my machine at work. And I don't have time to modify this. But it's a start.

What this code does is disable the controls (menu items)under Tools.

Dim cbr As Object
Dim cbc As Object

'***********************************************
'* Disable Privileged items from Menu bar(s) *
'***********************************************

Set cbr = CommandBars("mnuMain").Controls("Tools")

For Each cbc In cbr.Controls
cbc.Enabled = False
Next cbc
 
Thanks! It's a bit helpful, though I am trying to achieve the opposite :). So what's the command for adding the menu item (couldn't find in the manual)? And how can you refer to the existing menu. Let's say "Edit" or "File" menu?

regards,
rydel n23
 
What I do is create my own menubar and toolbar and customize it. Then I don't have to worry about adding items at startup. However, sometimes it is necessary. So here's some code on how to do it. Note that you will have to set a Reference to "Microsoft Office 9.0 Object Library" if you want to be able to declare items as CommandBarControls. Else just declare the variable as an Object.

The following code adds a combobox to the main menu. The public function "NewItem_OnClick" is called when the user selects an item.

Dim cbcControl As CommandBarControl

On Error Resume Next

Set cbcControl = CommandBars("Menu Bar").Controls("NewItem")

If (Err.Number = 5) Then 'IFT, "New Item"
On Error GoTo ErrHandler

Set cbcControl = CommandBars("Menu Bar").Controls.Add(msoControlComboBox) '(msoControlButton)

With cbcControl
.Caption = "Show:"
.Tag = "NewItem"
.OnAction = "NewItem_OnClick"
.Visible = True
.Style = msoComboLabel
.BeginGroup = True
.DescriptionText = "Select Item"
End With

End If

Public Function NewItem_OnClick()

Dim cmbBar As CommandBarControl

Set cmbBar = CommandBars("Menu Bar").Controls("NewItem")

Msgbox cmbBar.Text

End Function
 
Hi FancyPraire,

Am I mistaken or does the code you suggested to disable
* Disable Privileged items from Menu bar(s) *
disable all across all access databases in your
windows applications. I found that using this for i.e.
Tools on the Menu Bar disables Tools on all Menu Bars
in all Access applications on our pc's in our company.

Great code except be careful using it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top