Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eval with a variable name ?!? 1

Status
Not open for further replies.

gazolba

Programmer
Joined
Dec 4, 2001
Messages
167
Location
US
I'm trying to do the following but I alawys get a message that the function is not found.

Dim Func as string
Func = "MySub()"
Eval(Func)

According to Access Help this should work but I can't get it to. I'm using Access 2K
 
Is MySub a sub or a function? If it's a sub, it will not return a value to your Eval function.

The error message is telling you that the Eval function cannot find a function named MySub.

Tranman
 
It is a function and it does exist.
I've been able to get the following to work:

Eval(MyFunc())

but not

Eval("MyFunc()")

and not (and this is what I need)

MyF = "MyFunc()"
Eval(MyF)

I always get "The expression you entered has a function that <name> can't find
 
gazolba,
You'll love this...

Private Sub xxx()
Dim strFunName As String
Dim strxxx As String
strFunName = "MyFun()"
strxxx = Eval(Eval(strFunName))
End Sub

Public Function MyFun() As String
MyFun = "6+6"
End Function

Believe it or not, the inner Eval returns "6+6" and when you Eval that Eval, you get 12, just like you would want.

Go figure...

Anyway, this will let you pass a function name to an Eval as a variable and get an appropriate value in return.

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top