Actually, it works the same as menu bars work now. About 99% of my current
custom menu bars call VBA code. You simply use the "on -action" setting of
the menu, and place the function name in the menu.
eg:
=MyFunctionName()
Of course, it is common to have code in a form, and if you make the function
in the form public, then the on-action above would run a public function in
the form. This is a great feature, since then if a DIFFERENT form has the
focus, the same menu bar can run different code.
for example, virtually ALL of my forms have a public function to delete the
record. It is always called
=MyDelete()
Even more interesting if the current form with the focus does NOT have that
public function, then a public function of that name in a standard code
module is executed (so, for most forms, I assume that "id" is the delete
key, and thus I use a generic public function for all forms. For those forms
that need to check for child records, or other types of things, I then place
a public function in the form.
I have tested the behaviours of the new ribbon bar, the above approach also
works.
If you going to place a global function in a module (that catch all concept
I mentioned), then
often, (if not most of the time), you code you call will need to pick up
some information about the 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.