Can I run formulas from a text field?

M

Marc H

I need to calculate a dollar amount for differently in each line of a table.
I have a [CalcMethod] field and currently use a SELECT CASE structure to do
the calculation depending on the value in [CalcMethod] and place the value in
[Total]. ex. In row 1 of the table the calculation is [Total] = [Volume] *
[Price]. In row 2 the calculation is [Total] = [Volume] * [Units] *
[UnitPrice]. In row 3 the calc is [Total] = [Volume] * [Charge] *
[PercentofCharge]. These formulas are hardcoded into the SELECT CASE
structure.

I would like to have a table with id and text fields with these formulas
loaded in the text field, then find the formula using the id and run it. This
would allow me to add new formulas on the fly. Can I do this?
 
K

Klatuu

Look in VBA for the Eval function. It is used to convert a string to an
expression and execute it. For example:

strExpr = "5 * 25"

x = Eval(strExpr)
x will now = 125
 
M

Marc H

So simple! Thanks.

Klatuu said:
Look in VBA for the Eval function. It is used to convert a string to an
expression and execute it. For example:

strExpr = "5 * 25"

x = Eval(strExpr)
x will now = 125

Marc H said:
I need to calculate a dollar amount for differently in each line of a
table.
I have a [CalcMethod] field and currently use a SELECT CASE structure to
do
the calculation depending on the value in [CalcMethod] and place the value
in
[Total]. ex. In row 1 of the table the calculation is [Total] = [Volume] *
[Price]. In row 2 the calculation is [Total] = [Volume] * [Units] *
[UnitPrice]. In row 3 the calc is [Total] = [Volume] * [Charge] *
[PercentofCharge]. These formulas are hardcoded into the SELECT CASE
structure.

I would like to have a table with id and text fields with these formulas
loaded in the text field, then find the formula using the id and run it.
This
would allow me to add new formulas on the fly. Can I do this?
 

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