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

x
?
Solved

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

Posted on 2013-05-23
7
Medium Priority
?
311 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 2000 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
Independent Software Vendors: 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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