Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Assigning a module to a menu button (onclick event)

Posted on 2011-02-17
16
Medium Priority
?
1,004 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:Gruffman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +1
16 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 34921822
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
 
LVL 85
ID: 34921935
What do you mean by "menu item"? Are you referencing a ribbon item? Or are you using the term for something else?
0
 
LVL 75
ID: 34921945
"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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Gruffman
ID: 34921952
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
 
LVL 75
ID: 34921970
You need to include the Equals sign ... and no quotes ... see image above

mx
0
 
LVL 28

Expert Comment

by:omgang
ID: 34921978
Where did you create the Function StartPDfEmail?  Did you make it a public function?
OM Gang
0
 

Author Comment

by:Gruffman
ID: 34921986
Okay, did that, but now geting a compile error - "expected variable or procedure, not module"
0
 

Author Comment

by:Gruffman
ID: 34922006
StartPDFEmail is a not a function, it's a Public Sub.
0
 
LVL 75
ID: 34922016
"it's a Public Sub."

It needs to be a Public Function, not Sub

mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 100 total points
ID: 34922022
Everything you need is @ http:#a34921945

mx
0
 

Author Comment

by:Gruffman
ID: 34922134
Thank you.
0
 
LVL 28

Expert Comment

by:omgang
ID: 34923071
My first post shows how to use a function to call a sub.
OM Gang
0
 
LVL 75
ID: 34923106
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
 
LVL 28

Assisted Solution

by:omgang
omgang earned 100 total points
ID: 34926271
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
 

Author Closing Comment

by:Gruffman
ID: 34927058
A function to call a function, interesting.
0
 
LVL 75
ID: 34927767
@omgang:
ok.

mx
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question