Run Time Error 5 Invalid Call or Argument

G

Greg Maxey

I added a New Menu to the menu bar. I named it Test Menu and added one
control named Test.

When I try to run the following code I get a Run Time Error 5 Invalid
Call or Argument:

Sub Test1()
CommandBars("Test Menu").Controls("Test").Enabled = False
End Sub

On the Table Menu I have a Control name "Table Data"

If I run:

Sub Test2()
CommandBars("Table").Controls("Table Data").Enabled = False
End Sub

It runs fine.

What could be causing the error with Test1?

Thanks.
 
J

Jezebel

The difference is that the Commandbars("Table") exists (that's the Table
toolbar, not the Table option on the main menu). You need CommandBars("Menu
Bar").Controls("Test Menu").Controls("Test").

You might find it simpler to assign a tag value when you create the control,
then use the CommandBars.FindControl function to retrieve it.

The commandbars object model is a nightmare at the best of times. The
problem with retrieving controls by name is that there's no requirement that
control names be unique.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top