Problem with Eval() function

785
2
01-09-2012 02:26 AM
NeilWebber
New Contributor III
Hi
I wonder if someone can point out where I'm going wrong here.
I'm trying to use the Eval() function from Microsoft Access in Arc9.3 vba environment.
I have a brand new mxd with the Microsoft Access object library referenced and all functions are in a standard module. A simple test as follows, as per the msdn example (and what works in Access):

Public Function SHLtest()
Dim fncXXX As String
fncXXX = "fncTest()"
Eval (fncXXX)
End Function

Public Function fncTest()
MsgBox "fncTest"
fncTest = True
End Function


This does not work - get Runtime error 2425 (function name can't be found)

However, the below does work, where the function name is just passed in without any quotes etc (i.e. it looks like a variable name but is treated as a string):

Public Function SHLtest() '''works
Eval (fncTest)
End Function

Public Function fncTest()
MsgBox "fncTest"
fncTest = true
End Function


Does the Eval() just not work this way in Arcmap vba, or have  I fundamentally misunderstood something, made a dumb error etc?

As an aside, I want to use the Eval function to call procedures where the procedure name is a variable. A user interaction results in a procedure name (and parameters) being passed in from an Access table and I then want that procedure to be executed via the Eval function. Maybe someone can suggest a better way
many thanks
Neil
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Neil,

I had a play with the eval() function and was able to replicate the issue you have. For what it's worth I couldn't work out how to get it to call the function, it must be quirk of VBA in ArcMap.

Duncan
0 Kudos
NeilWebber
New Contributor III
Thanks for your input Duncan - good to know it's not just me.  I have reverted to using the IVbaApplication.RunVBAMacro method to achieve what I want.
Although I do still wonder why Eval() behaves like that in Arcmap VBA.
--Neil
0 Kudos