Execute code from string

  • Thread starter Georgios Liakopoulos
  • Start date
G

Georgios Liakopoulos

Hi,
I wish to create a form which will allow the user to enter a function
which will use fields (parameters) from a table to calculate the values
of another field. Since the parameters and the function itself is not
constant, I want to 'translate' the input formula to code. So, here is
an example:
Parameters: parA, parB, parC, etc.
User enters function: strCalc = "parD = (parA + parB) / parC"
I can make a DAO recordset (rst) of the table and also convert the
string to look like: strCalc = "rst!parD = (rst!parA + rst!parB) /
rst!parC".
The problem is: how will I execute this code?
I've tried:
Eval(strCalc)
but produces an error: 'Runtime error 2423: The expression you entered
has an invalid .(dot) or ! operator or invalid parentheses'
The same error is produced even with simpler functions like strCalc =
"rst!parD = rst!parA".

Thanks for any help
 
A

Access Developer

I responded in the microsoft.public.access group. It usually is not
productive to "multipost" as you did; if you feel compelled to have it
appear in more than one newsgroup, "crossposting" so all those newsgroups
are listed in the headers is much better... many newsreaders will display
all the responses, so I could see if I'd answered before, rather than just
remembering as I did here.

Be sure to see what I suggested you need to do... we do not have your
database in front of us, so all we have to go by is what you write for us...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top