[Webinar] Streamline your web hosting managementRegister Today

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 MVP, Access and Data Platform)Commented:
Try this:

Dim VarName

VarName = "YourFunctionName()"

Call Eval(VarName)
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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 MVP, Access and Data Platform)Commented:
Not necessary ...

Dim sQryName As String

sQryName = "YourQueryName"

DoCmd.OpenQuery sQryName
0
 
geeta_m9Author Commented:
Great, thanks!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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