tags:

views:

232

answers:

4

Is there a way to execute a literal such as,

 UseValueKey = ExecuteMethod("Date()")

I want to have the variable UseValueKey return the actual date.

I am using VBA.

Any ideas?

+5  A: 

I haven't done any VBA coding for several years, but I recall that Access VBA had an Eval() method that could be used to evaluate code represented as a string.

This article gives an example of its usage.

pmarflee
+2  A: 

You can try the Eval function.

Colin
A: 

Perhaps I'm not exactly following you, but you should be able to use

Date

for example

UseValueKey = date
Praesagus
+1  A: 

If, as indicated in the question comments, the function name is known and can be delivered as a method on a class, try looking at

CallByName object, routine, callType

where callType indicates whether the called routine is a property Get/Let/Set or a Method.

It feels a lot less kludgey (and somewhat better controlled) than fooling with code evaluation, where you may be leaving yourself open to, er, unexpected consequences...

Mike Woodhouse