Solved

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

Posted on 2013-05-23
7
301 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
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This article will show you how to use shortcut menus in the Access run-time environment.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now