Can I run formulas from a text field?

  • Thread starter Thread starter Marc H
  • Start date Start date
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?
 
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
 
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?
 
Back
Top