place BuiltIn control on commandbar with VB

Hello experts,

In Access 2000 when I do customize a commandbar thrue the menu I can click on the 'commands' tab next I can place a form on my commandbar by drag and drop.

When I check in VB the type and Id and parameter I get the following results:
Type = 1,  Id=1837, Parameter="myFormName"

Then I try the following code:

commandbars("Mybar").controls.Add type:=1, id:=1837, parameter:="myFormName"

I get a runtime error: automation error

When I place a not builtIn-control then it works OK, but as soon I use id:= it does'nt work.

What I'am doing wrong

greetings DataMaat
LVL 1
DataMaatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Most of the built- in  controls work like that.  Unfortunately, 1837 for opening a specific form and it's report counterpart (1838, I believe do not work that way).

A good workaround is to make a "template" commandbar with any form on it, like you did initially.  Call this commandbar "MyTemplate"  Set the caption property of the openform button on your template commandbar to "Openform".  

You can then use VBA to copy the "openform" button to MyBar, and set its properties so that it opens whatever form you need:

Function CreateFormButton()
   dim obj as office.commandbarbutton
   
  'Copy the openform button to MyBar
   obj = Commandbars("MyTemplate").controls("OpenForm").copy Commandbars("MyBar")
  'Set its properties for the form you want to open
   obj.parameter = "Form1"
   obj.caption = "form1"

  'Copy the openform button to MyBar
   obj = Commandbars("MyTemplate").controls("OpenForm").copy Commandbars("MyBar")
  'Set its properties for the form you Want to open
   obj.parameter = "Form2"
   obj.caption = "form2"

'etc...

end function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DataMaatAuthor Commented:
Thanks a lot,

I've rewrite my code and it works fine for me.

But it is still strange you can't use the buitlin id's when you want add a builtin control

greetings from Holland.

DataMaat
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.