CommandBars coding acting weird...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to get a handle on coding for Command Bars, a very tricky subject
to say the least. I thought I had it down but every time I tried to use code
to create a CommandBar, I got the infamous ("Invalid Procedure Call") error
message.

So in despair I tried copying a Command Bar code right form MS website.
When I tried to run that I got the same message. Here's the code:

Sub testAddModifyToolbars1()
Dim myBar as CommandBar
Dim oldcontrol as CommandBarControl

Set mybar = CommandBars _
.Add(Name:="ChangingButton", Position:=msoBarTop, _
Temporary:=True)
mybar.Visible = True
Set oldcontrol = mybar.Controls _
.Add(Type:=msoControlButton, _
ID:=CommandBars("Standard").Controls("Copy").ID)
oldcontrol.OnAction = "changeFaces"
End Sub


Can someone tell me whats wrong and why even MS's code doesnt seem to work?

Thanks,

Bill
 
I'm not sure you can do a continuation in the midst of instantiating an
object like that.

See whether this works any better:

Sub testAddModifyToolbars1()
Dim myBar as CommandBar
Dim oldcontrol as CommandBarControl

Set mybar = CommandBars.Add( _
Name:="ChangingButton", Position:=msoBarTop, _
Temporary:=True)
mybar.Visible = True
Set oldcontrol = mybar.Controls.Add( _
Type:=msoControlButton, _
ID:=CommandBars("Standard").Controls("Copy").ID)
oldcontrol.OnAction = "changeFaces"
End Sub
 
Hi Doug,

I get same error message as before. Freakin weird. Your code looks perfect
to me but it doesnt work. I have all my References set properly.

Damn who the heck knows.

Bill
 
Bill Mitchell said:
Hi,

I'm trying to get a handle on coding for Command Bars, a very tricky
subject to say the least. I thought I had it down but every time I
tried to use code to create a CommandBar, I got the infamous
("Invalid Procedure Call") error message.

So in despair I tried copying a Command Bar code right form MS
website.
When I tried to run that I got the same message. Here's the code:

Sub testAddModifyToolbars1()
Dim myBar as CommandBar
Dim oldcontrol as CommandBarControl

Set mybar = CommandBars _
.Add(Name:="ChangingButton", Position:=msoBarTop, _
Temporary:=True)
mybar.Visible = True
Set oldcontrol = mybar.Controls _
.Add(Type:=msoControlButton, _
ID:=CommandBars("Standard").Controls("Copy").ID)
oldcontrol.OnAction = "changeFaces"
End Sub


Can someone tell me whats wrong and why even MS's code doesnt seem to
work?

There doesn't seem to be any existing command bar named "Standard"; at
least, not in my copy of Access 2002. Is that an exact quote from the
code you got from the web site? Please post a link to the source of the
code.

I find that if I replace "Standard" with "Database", the code works
fine.
 
As Dirk says, there is no 'Standard' toolbar in Access. Probably the code
you got from Microsoft's web site was for Word or Excel?

The following code will list to the Immediate window the names of all the
built-in Access command bars ...

Public Sub TestSub()

Dim obj As CommandBar

For Each obj In Application.CommandBars
Debug.Print obj.Name
Next obj

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Dirk Goldgar said:
There doesn't seem to be any existing command bar named "Standard";
at least, not in my copy of Access 2002. Is that an exact quote from
the code you got from the web site? Please post a link to the source
of the code.

I find that if I replace "Standard" with "Database", the code works
fine.

The code works unchanged in Excel, so I expect that Access just has a
different set of built-in toolbars from the rest of the Office suite.
 
Back
Top