error with the Eval() function (1 Viewer)

FireStrike

Registered User.
Local time
Today, 03:29
Joined
Jul 14, 2006
Messages
69
I have a string that has only a function name in it. I want to call the function name that is in the string. my function is called goodtime. I have the following code.

Code:
Public Function goodtime() As String
    DoEvents
    goodtime = "testing"
End Function
Code:
       strTemp = strAnswer & "()"
        strAnswer = Eval(strTemp)

When I run this at the eval statement I get the following error.

The expression you entered has a function name that microsoft office access can't find

I cannot figure out why, if I just run
strTemp=goodtime()
then it works fine. Does anyone have a clue why this is not working?
 

pdx_man

Just trying to help
Local time
Today, 00:29
Joined
Jan 23, 2001
Messages
1,347
So, I am assuming that you must have something like this, which wasn't included in your statement?


strAnswer = "goodtime"

and you are trying to dynamically call different functions?

This works fine for me. I am guessing you are not initializing strAnswer:

Code:
Public Function tester34() As String
    tester34 = "Hello World"
End Function


Public Sub workit()

Dim TheName As String
Dim TheFunc As String
Dim TheFuncName As String

TheFuncName = "tester34"
TheFunc = TheFuncName & "()"
TheName = Eval(TheFunc)

Debug.Print TheName

End Sub
 

Users who are viewing this thread

Top Bottom