Help needed Programming command bars

Hi
I really need help  with this so I'm reasking the question and giving it 500 pts:

I'd like to programatically add a commandbar button (msoControlButton) to a 'menu' (msoControlPopup) and I'd like it to behave the same was as if I'd have manually chosen to:
1. customize the menu bars, created/selected my custom toolbar,
2. Dragged on to that toolbar a 'NewMenu'
3. On to that new menu, dragged a 'form', from the AllForms section


AFAICT, this means that my commandbutton has to have a builtin ID of 1837 and a parameter which is the  name of the desired form.

so here is what I imagine the code should resemble:
 Dim z As CommandBarButton
 Set z = Application.CommandBars("MyMenu").Controls(1).controls.Add(msoControlButton, 1837, "Form1")

When I try this I get this error:
  -2147467259(800004005) 'Method "Add" of object commandbarcontrols failed' -
thx
Glenn
LVL 2
valhallatechAsked:
Who is Participating?
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.

harfangCommented:
"AFAICT", you have all the right assumptions... But, I never got this to work.
But I have two workarounds:

1) the one I ended up using is this:

    With Application.CommandBars("MyMenu").Controls(1)
        With .Controls.Add
            .Caption = "Form1"
            .FaceID = 1837
            .OnAction = "= DoCmd.OpenForm(""Form1"")"
            .TooltipText = "Open Form1"
        End With
    End With

2) if you really need a BuiltIn Id 1837 command button:
Create a "template" toolbar (hidden, etc...) with one of them and go:

    CommandBars("Template").Controls(1).Copy _
        CommandBars("MyMenu").Controls(1).CommandBar

And then customize the new button. I suspect there is an other "CreateCommandButton" method which is not available to us, used in the "Customize" screen.

Good Luck
0

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
valhallatechAuthor Commented:
Thanks harfang - sorry its been almost 2 mths, I haven't been around -

I was afraid this was the news - this kind of  'not available to us' type of 'behaviour' is one of the maddening things about access and proprietery software in general.

I'm trying to build a utility to integrate my access work into the same production processes as my other work, and that involves using subversion and/or cvs as source control - except for this little quirk, I think i'd pretty much be there.

I'll have a play with these workarounds - as they at least let me get on.

thanks again for the 'bad news' - I can stop holding out for the perfect solution
0
harfangCommented:
Yeah, we loose much time with these problems...
The "custom button" solution works fine, though, and is transparent to the user.

Good luck with your project!
0
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.

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.