Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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

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
geeta_m9
Asked:
geeta_m9
  • 4
  • 3
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Try this:

Dim VarName

VarName = "YourFunctionName()"

Call Eval(VarName)
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Don't forget the parens.

OR do this:

VarName = "YourFunctionName"

Call Eval(VarName & "()")
0
 
geeta_m9Author Commented:
Yes, both the solutions work. Thank you!
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
geeta_m9Author Commented:
Would I need to use the same method if I called a query within a variable?
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Not necessary ...

Dim sQryName As String

sQryName = "YourQueryName"

DoCmd.OpenQuery sQryName
0
 
geeta_m9Author Commented:
Great, thanks!
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.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now