IIf then? to Calculate on Checkbox on a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On my form - when a checkbox is checked I need to multiply two fields from
different tables and save the product to a third field in a table for future
reporting use. How can I do this?
thanks!
 
Kay said:
On my form - when a checkbox is checked I need to multiply two fields
from different tables and save the product to a third field in a
table for future reporting use. How can I do this?
thanks!

It is better in the vast majority of cases to show the calculation in a
query rather than save it.
Assuming the tables are related:
Answer:IIF( Yourcheckbox = True, FieldfromTable1 * FieldFromTable2, "")

does what you want and solves the problem of having to write more code if
the box is unchecked for some reason (even if the reason is "oops") and a
variety of other problems.

If the tables are not related you may have to use dLookup to find the
values.
 
Mike,
thank you so much! These tables are not related but I think it's time they
became more acquinted as I have four fields which may need calculations.

I don't understand not wanting to store data in a table from a calculation.
In this case the product stored will later be calculated in a report so I
need the value.

thanks again, Kay
 
Kay said:
Mike,
thank you so much! These tables are not related but I think it's time
they became more acquinted as I have four fields which may need
calculations.

I don't understand not wanting to store data in a table from a
calculation. In this case the product stored will later be calculated
in a report so I need the value.

The same query used to do the calculations would be used in any forms and
reports.

You only have to write a minimum of code and don't have to worry about a
value being changed in some other form that does not contain the code to
update a field.

If for example you stored the result of somebody buying 10 widgets at $1.98
in a totals field (19.80) and later somebody changed the price and number
purchased in another form or directly to the table the results of 1000
widgets at $10.00 each would still cost the customer $19.80.
 
Back
Top