"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:iKagd.14036$5O4.2722@trnddc07...
Back in the old days before I started learning about menubars (the day
before yesterday,) I based all my operations on command buttons on the
forms. Now the forms are all cluttered up with buttons so I'm beginning
to
clean it up using menubars.
Great stuff. I also find that menus can significantly clean up those forms.
So far, I haven't used ANY macros. But some some websites, as well as my
book, seems to indicate that it is necessary to base the menubar on a
macro
with each menu's first instruction being AddMenu.
No, not all. As a general rule, I simply have all my menus call custom code.
That code can be in the forms module, or a general module.
In most cases, if the menu bar code is for the current form..then it makes
sense that the code belongs in the forms module..and not some other module.
Here is a few other points:
You do in fact have to use a function name..and you can't use a sub-name. If
you already got some extensive sub code written, you then just create a
function that calls the code.
The functions in the form have to be public. For example, MOST of my forms
have some custom delete code, and I ALWAYS call it
Public Function MyDelete
The advance of ALWAYS using the same function name should not be missed. If
you have a custom menu bar, then to call the forms code you put the function
name in the menu "on action" (I create all my menus via drag and drop with
the mouse by the way!).
So, to run the MyDelete function, you just type in the following into the
menus "on action" property setting:
=MyDelete()
The above goes in the on-action. What is very cool here is that this means
that ONE menu bar can apply to several forms. Which ever form has the focus
will have its public function called MyDelete() run. And, if the form does
NOT have a public function, then a function of the above name in a standard
module is tried to run. So, for example, you could write a common delete
function that applies to ALL forms,a and place the code in a standard
module. However, lets assume you have one form that needs special
treatment...you just then put a public function in the forms module of the
same name..and that one gets run!
Further, a LOT of my menu code is in standard modules, and some is in forms
module. If the code goes into a forms module, then you code can use things
like:
me.Refresh
or me.InvoiceNumber
However, for code in a general module..you can't use "me", so you what you
do is simply pick up the currently active form.
So, for "general" code, my code almost always grabs the active form...here
is a example for a invoice print option:
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
So, you can see that the trick here is to "pick up" the currently active
screen, and make a form ref that you can use. As mentioned, if you place
your menu bar code in the actual forms module..then you can use "me".
Here is some other ideas and screen shots of menu bars I made in ms-access
(all were created via drag and drop).
http://www.attcanada.net/~kallal.msn...erFriendly.htm
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com http://www.attcanada.net/~kallal.msn