Menu Item Parameter -> Macro Confusion

  • Thread starter Thread starter Luke Dalessandro
  • Start date Start date
L

Luke Dalessandro

Hi Everyone,

*Using Access 2000*

Summary: How do I pass/reference a Menu Item's "Parameter" variable
into/inside a Macro to pass it to a function (using "RunCode") that
takes a string parameter, or how do I call the function directly from
the Menu Item without using the Macro?

Thanks,
Luke

*************************************************
** More detail to describe the situation below **
*************************************************
Brief table description:

MainRecords(MainRecordID, ...)

Events(EventID, MainRecordID, Type, Date, User, ...)

There is a one-to-many relationship between the two tables on
"MainRecordID".

There are a bunch of different types of events that can occur for a
record. Entry of event data is controlled by popup "data entry" forms.
So as a simple example, two types of events are "Called" and "Closed."

My two forms would be named "Event_popCalled" and "Event_popClosed."

I have a module procedure that pops forms for me based on a passed
string form name.

Public Function Event_AddEvent(strPopFormName as String) As Boolean
DoCmd.OpenForm strPopFormName
Event_AddEvent = True
End Function

The actual situation is more complicated, but this demonstrates my question.

I have a Menu that has an "Event" menu group. Within the group I have
menu items that corerespond to the different events available.

Events
Add Call
Close Record

From the "Add Call" and the "Close Record" Menu Items I want to call

Event_AddEvent("Event_popCalled")
Event_AddEvent("Event_popClosed")

Respectively.

When I set the Menu Item's command to "Event_AddEvent" directly, it
can't find the function (it's looking for a callback function?), so I
created a macro that has one line: "RunCode". I point run-code at my
"Event_AddEvent" function, which works fine.

My problem is that I can't figure out how to reference the Menu Item's
"Parameter" variable (set to the form name) inside the Macro to pass it
to my function... I don't want to have one macro per Menu Item because
it gets too cluttered. Any help would be great.

Thanks in advance,
Luke
 
Just put the name of the function in the custom menus on-action setting.

=MyprintInvoice()

The above would call a PUBLIC function called MyPrintInvoice() in the
current form. Do note, that if the function name does NOT exist in the
current form module, then the standard modules are searched, and the
function is run from that module. This is rather nice, as you can thus make
custom menus that behave differently since the forms module coded is looked
at first for the code to run.

And, if you need be, you can most certainly pass values from the above like:

=MyPrintInvoice("speical")

However, once you jump into the world of custom menus, then usually having
the button simply call code in the particular form is the best approach.
And, if the button code is to operate on more then one form, then you can
write generic code that picks up the current screen.

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

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.

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

http://www.attcanada.net/~kallal.msn/Articles/UseAbility/UserFriendly.htm
 
Albert,

You're a lifesaver... It was simply the "=" sign that was causing all of
my trouble. Without the "=" it can't find the function, and that was
what was causing me so much pain.

Thanks a million.
 

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

Back
Top