Code for Custom Toolbar?

M

mj4711

I've created a custom toolbar in Access 2003 using the "point, click, drag"
method within the current project. I would like to modify the toolbar at the
code level (i.e., VBA), but I can't seem to find where the code exists for
this toolbar. I've tried searching all of my modules using keywords, but to
no avail. Can someone tell me how to get to the code that Access wrote
"behind the scenes" while I blithely clicked and dragged to create the
toolbar?

Thanks!
MJ
 
M

mj4711

P.S. The "On Action" in the customize dialog box is blank for all the
buttons, so I don't know what function is associated with them...

MJ
 
A

Albert D. Kallal

Well, there is no code generated for a form or a report either (unless you
add custom code to that form/report).

Either that custom menu bar runs built-in buttons, or custom buttons can run
your standard vba code.

If the button runs standard vba code, then you find the name of the
function the button runs when clicked on by looking at the buttons on-action
setting
(you can view this property when you are in design mode for a menu bar).
 
A

Albert D. Kallal

mj4711 said:
P.S. The "On Action" in the customize dialog box is blank for all the
buttons, so I don't know what function is associated with them...

If the on-action is blank, then it means the button is a built in one, not
one that calls your vba code.

In that case, just look at the screen tip and the parameter. For example, if
I build a custom menu bar, and add a "form" to the menu bar, you see the
following settings:

Caption :Form1
ShortcutText :
Screen Tip :Open form 'Form1'
On Action :
Style :
Parameter :Form1

So, by look at the above, you can well see it launches form1, but it using a
built option, not code.

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()

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 in
the forms code module. So, the button code WILL call the routine in the
current form that has the focus (thus allowing you to use the same menu
bar for different forms and run **different** code for that same button).

If you want to see some sample menu bars, and why I use them, you can read
the following:

http://www.members.shaw.ca/AlbertKallal/Articles/UseAbility/UserFriendly.htm
 

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