place BuiltIn control on commandbar with VB

Posted on 2006-04-06
Last Modified: 2008-02-01
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
Question by:DataMaat
    LVL 61

    Accepted Solution

    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"


    end function

    LVL 1

    Author Comment

    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.


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now