Assigning a module to a menu button (onclick event)

I want to assign a VB module to a menu button and have the code executed upon the OnClick event; however, I'm not finding the method to accomplish this via the OnClick options.  My research indicates that this call to the module must be made through an establshed function...? Seems straight forward enough but my feeble attempts to make this work have failed.  Any assistance is appreciated.
GruffmanAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Everything you need is @ http:#a34921945

mx
0
 
omgangIT ManagerCommented:
You don't actually call a module.  You can call a function.  The trick is you can create a function whose purpose is to call a sub.

Private Function CallSub()

    Call MySubProcedure

End Function


Now you set the OnClick event to the function CallSub, e.g. =CallSub()

OM Gang
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What do you mean by "menu item"? Are you referencing a ribbon item? Or are you using the term for something else?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"My research indicates that this call to the module must be made through an establshed function."

Not the case.

Say this is the Function you want to call, either in a Form Module or VBA Module

Public Function mMyCoolFx()

 ' code does whatever

End Function

On the property sheet of the command button - Event tab ... do this - see image,

mx
Capture1.gif
0
 
GruffmanAuthor Commented:
I created the function but when I click on the menu button I get an error message that Access can't find the object "StartPDfEmail" (my function).  I typed the name of this function on the "OnClick" line in properties for this button - is that the correct method?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You need to include the Equals sign ... and no quotes ... see image above

mx
0
 
omgangIT ManagerCommented:
Where did you create the Function StartPDfEmail?  Did you make it a public function?
OM Gang
0
 
GruffmanAuthor Commented:
Okay, did that, but now geting a compile error - "expected variable or procedure, not module"
0
 
GruffmanAuthor Commented:
StartPDFEmail is a not a function, it's a Public Sub.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"it's a Public Sub."

It needs to be a Public Function, not Sub

mx
0
 
GruffmanAuthor Commented:
Thank you.
0
 
omgangIT ManagerCommented:
My first post shows how to use a function to call a sub.
OM Gang
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
But why would you want to do that?
I *never* ever use Subs. To me they are totally useless in today's world.

mx
0
 
omgangConnect With a Mentor IT ManagerCommented:
mx, understood.  I interpreted the original Q as to how to call a Sub Procedure directly from the OnClick action of a command button.  A method to do so is to create a function to call the sub.  Now this should seem silly to just about anyone who goes through the excercise since simply converting the called Sub to a Function (as you suggested) provides solution in fewer lines of code.
OM Gang
0
 
GruffmanAuthor Commented:
A function to call a function, interesting.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
@omgang:
ok.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.