Solved

How do I call an Access procedure whose name is contained in a variable?

Posted on 2013-05-23
7
307 Views
Last Modified: 2013-05-23
Depending on the user selection, I would like to call any one of a number of procedures. This is done in a different section of the program so I stored the name of the procedure in a variable, e.g., VarName. When I tried calling the procedure later using Call VarName, it didn't work. I obtain the error, "Compile Error: Expected procedure, not variable".

How can I fix this?
0
Comment
Question by:geeta_m9
[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
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 39192665
Try this:

Dim VarName

VarName = "YourFunctionName()"

Call Eval(VarName)
0
 
LVL 75
ID: 39192669
Don't forget the parens.

OR do this:

VarName = "YourFunctionName"

Call Eval(VarName & "()")
0
 

Author Comment

by:geeta_m9
ID: 39192671
Yes, both the solutions work. Thank you!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 39192687
You are welcome.
Look up Eval() in Help ... VERY helpful for this sort of thing and many others.
Although Help is not that helpful on this per se :-(
0
 

Author Comment

by:geeta_m9
ID: 39192702
Would I need to use the same method if I called a query within a variable?
0
 
LVL 75
ID: 39192721
Not necessary ...

Dim sQryName As String

sQryName = "YourQueryName"

DoCmd.OpenQuery sQryName
0
 

Author Comment

by:geeta_m9
ID: 39192725
Great, thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

730 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