Benjamins via AccessMonster.com said:
Please help.
I need to have a menu bar to replace all my current command buttons. Is
there
a way to do it
Thanks.
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 "menu" 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 xnumber 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.
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
While you can and often will create a completely new custom menu bar for a
given form, if you're smart about your designs, you can certainly have one
menu bar that can be used over and over for many of your forms. Each menu
option on the menu var can call a particular function. For example in almost
all of my forms I have a public function called MyDelete. This deletion
routine checks things like related tables, and has the ability to give nice
user friendly messages to the end user before the attempt to delete a
record. Thus, by following this coding standard, I can actually use the
same custom menu bar for different forms, as long as each formed as a public
function called mydelete. so, what this means is that the form currently in
focus will decide which code (mydelete) gets run in what form.