permanent custom module toolbar commands

J

johngo

To create custom toolbar commands in a module toolbar, in 2000 and
later, you have to use VBE.CommandBars and set the CommandBarControl
OnAction property to the custom function. I am setting it to a
function in a library db.

Every time I open Access, I have to reset the OnAction property.

How do you set it once?
 
A

Albert D. Kallal

johngo said:
To create custom toolbar commands in a module toolbar, in 2000 and
later, you have to use VBE.CommandBars and set the CommandBarControl
OnAction property to the custom function.

no, you do not!!

I mean, you can use code to make a menu bar, but just like buildign a form,
you *can* use code, but most of time we use the mouse and drag and drop to
create forms. We also do the same for custom menus.

Most certnaly my custom menus call my vba code, but I sure as the heck don't
need to write code to create menus.

Any reason why you don't just use the mouse...create the menus, and have
those menus call your code?
 
J

johngo

Albert said:
no, you do not!!

I mean, you can use code to make a menu bar, but just like buildign a form,
you *can* use code, but most of time we use the mouse and drag and drop to
create forms. We also do the same for custom menus.

Most certnaly my custom menus call my vba code, but I sure as the heck don't
need to write code to create menus.

Any reason why you don't just use the mouse...create the menus, and have
those menus call your code?
For version 2000 and later, with the VBE separated from the Access db
window, you can not add custom commands that run your code to menus or
toolbars in the module window. That is why you have to use code. The
manual methods you use for a form or report toolbar do not work in the
VBE environment.
 
A

Albert D. Kallal

For version 2000 and later, with the VBE separated from the Access db
window, you can not add custom commands that run your code to menus or
toolbars in the module window. That is why you have to use code. The
manual methods you use for a form or report toolbar do not work in the
VBE environment.

Sure they do. My menu code that worked in a97 now works just fine in a2003..

I would say that 90% of my custom menu bars call, and run my VBA code.

All you need to do is make the code (a function) public, and then simply
place the function name in the buttons on-action event code.

Further, likely often you will have specific code to a particular form, and
once again, you simply declare those functions (in that form) as public.

The syntax to call the code then is:

=YourFunctionName()

The above is placed in the on-action setting. I done this for years, and I
don't
know of any other way to have menus call/run code. The split of the ide
never changed the above, and what I done for years in 97, now works
just fine in a2003

Often, (if not most of the time), you code you call will need to pick up
some information about he current screen etc. So, my code most of the time
starts out, and grabs the current screen name. I use:

Public Function AskInvoicePrint()

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid

End Function

The above is code that the invoice print button runs. note how I right away
pick up the active form. After that, I can easily ref the forms object as if
the code was running much like the code would if put behind a button on the
form. In the above example, I also check if a invoice number has been
generated before printing. And, the Refresh forces a disk write if in fact I
do change the invoice number. And, in addition the above clip also passes
the currently selected sub-form item that the invoice print form needs.

Also, if the code you write is for the particular form, then as mentioned,
you can simply place the code into the forms module code. There is no need
to pick up the active screen...and you can use me. as you
always used.
 
G

Granny Spitz via AccessMonster.com

Albert said:
Sure they do. My menu code that worked in a97 now works just fine in a2003..

Albert, I think you've missed his point. He's talking about the toolbars in
the VB code editor window, not the Access window. Maybe the developer's
version is different, but the retail version of Access doesn't allow creation
of custom buttons on the toolbars in the VB code editor through the
*Customize* GUI. There's no on action property to set with the GUI on the VB
code editor toolbars, either. We've had to use code for these since Access
2000.
 
A

Albert D. Kallal

Albert, I think you've missed his point. He's talking about the toolbars
in
the VB code editor window, not the Access window.

Ah, I did miss the point...
Maybe the developer's
version is different, but the retail version of Access doesn't allow
creation
of custom buttons on the toolbars in the VB code editor through the
*Customize* GUI.

correct, I was 100% wrong. Thanks for pointing the above out (no the
developers edition of ms-access changes nothing, it just gives you the
package wizard..and that is a separate program anyway- -- the rest of
ms-access remains the same..).
There's no on action property to set with the GUI on the VB
code editor toolbars, either. We've had to use code for these since
Access
2000.

Right. once again, thanks for the heads up. And, to the original poster,
yes, you are 100% correct and I am 100% wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top