call function from string var

P

Pendragon

Access 03/winxp

I have a function which sets a string variable to the name of a public
procedure based on a case statement. How do I then execute the procedure
when the procedure name is stored in the string variable?

strGetProc = oCalc.GetRdTemplate(NumberOfTeams)

GetRdTemplate is the function which executes a case statement to determine
which procedure should be run. NumberOfTeams is the integer variable passed
to the function and is the criteria for the case statement.

What is my next line of code to properly execute the procedure now stored in
strGetproc?

All possible procedures from the case statement are in the module
mod_NewTourney. I tried

strGetProc = "modNewTourney." & strGetproc
Call strGetProc

and some variations but always get a sub or function not defined error.

Any help is appreciate!!

Happy Holidays!
 
A

Albert D. Kallal

to run a public function, you can go:

strFunc = "MyFunction()"

eval strFunc

And, to run a sub, you can go:

dim strGetproc as string

strGetProc = "MySubName"

Application.run strGetProc

So, "eval()" can be use for functions, and Application.Run can be used for
subs.

in fact, run can also execute public functions also...
 
J

Joe D

Pendragon:

Here's a code example that may help you with your situation:
------------------------------------------
Public Function FunctionCall()
Dim TheFunction As String
Let TheFunction = GetProcName(1)
Eval (TheFunction)
End Function

Public Function GetProcName(Selection As Integer)
If Selection = 1 Then
GetProcName = "TrialResponse()"
End If
End Function

Public Function TrialResponse()
MsgBox "This is the response.", , "Notice"
End Function
--------------------------------------------------------
Some key points: Use the Eval function, include the () in the function name
response, don't concern yourself with the module name - the function name
must be unique anyway.

HTH

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top