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?
 
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

0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.