?
Solved

Help needed Programming command bars

Posted on 2004-11-29
3
Medium Priority
?
342 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:valhallatech
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 12702446
"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
 
LVL 2

Author Comment

by:valhallatech
ID: 12978417
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
 
LVL 58

Expert Comment

by:harfang
ID: 12983674
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

579 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