Execute dynamic VBA code just like docmd.runsql(SQLtext)

I am trying to make my app flexible and accept code on the fly.

I am using msaccess 2003 for the frontend and MS SQL2000 for the backend.  I compile all projects and the users run an *.ade file.

currently I create the dynamic code in T-SQL and execute it on the SQL server.  This as it is not secure and could crash with the wrong code.  I want to execute the code locally and/or use VBA code.

So basically I would like to create a string like:

str2Exec = "=iif(Value = 1, "S", "C")"

Then Replace the "Value" with a real number:

str2Exec = Replace(str2Exec, "Value", 1 )

Then finally exec the string and save the result

strResult = RunVBA(str2Exec)


Any ideas on how to execute this code on the fly?
ScottGutmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dorbraxtonCommented:
Have you tried the Eval() function?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
harfangCommented:
Hello,

If your strings contain only standard VB operators and built-in functions, you can use "Eval":

    ? Eval(Replace(" IIf(Value = 1, ""A"", ""B"") ", "Value", "13"))

Cheers!
(°v°)
ScottGutmanAuthor Commented:
exactly what i was looking for!!

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.