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

x
?
Solved

Execute Procedure using Variable name

Posted on 2011-09-14
9
Medium Priority
?
312 Views
Last Modified: 2012-06-21
In MS Access is there a way to call procedure where the procedure name is referenced inside a variable name?

Example:  
 
Dim MyProcedureName as String
       MyProcedureName = "TheProcedure"

Call  MyProcedureName
0
Comment
Question by:leeroypitre
[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
  • 5
  • 3
9 Comments
 
LVL 21
ID: 36538385
You must use a macro.  

This is one of the few instances where a Macro can do something that can;t be done in VBA.
0
 
LVL 75

Accepted Solution

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

Dim MyProcedureName as String
       MyProcedureName = "TheProcedure"

EVAL(MyProcedureName)

mx
0
 
LVL 75
ID: 36538421
Specifically:


Public Function aaaaQuickTest() As Boolean

    Dim Fx
    Fx = "aaaTest5()"
    Eval (Fx)
   
End Function


Public Function aaaTest5()

    MsgBox "aaaTest5"
 
End Function

In the Immediate Window:

?aaaaQuickTest()
results in the Message Box being displayed.

mx
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 21
ID: 36538439
The Procedure has to be a function that you call using the Macro command RunCode

0
 
LVL 75
ID: 36538450
Back to your example:


Dim MyProcedureName as String
       MyProcedureName = "TheProcedure()"  ' add parens

EVAL(MyProcedureName)

and "TheProcedure()" needs to be a Function, not a Sub.

mx
0
 
LVL 21
ID: 36538471
mx, I forget about Eval. I started using macro for this back with Access 2.
0
 
LVL 75
ID: 36538494
Yeah ... no need for Macros now ... Eval() does it ....

mx
0
 
LVL 35

Expert Comment

by:Norie
ID: 36538682
If it's a sub can't you use Application.Run?
0
 
LVL 75
ID: 36538715
Yes ... that is correct ... like so

Public Function aaaaQuickTest() As Boolean

    Dim Fx
    Fx = "aaaTest5"   ' no parens this time
    'Eval (Fx)
    Application.Run Fx
End Function

Public Sub aaaTest5()

    MsgBox "aaaTest5"
 
End Sub

Forgot about the the Run Method, even though I've used it before.  Good for running code in an external db.

mx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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