Adding calculated values into a table field???

G

Guest

How can I place a calculated value on a form into a tebles field?
I have a form that uses a collected check box and a collected by customer
check box, i then have code that checks the values of these check boxes and
determines a delivery charge value(we charge delivery both ways)

My question is this, how can i add that calculated value in to a table or
query so that when i print the invoice the delivery value is included?

Can anyone help?
 
W

Wayne Morgan

Are the checkboxes bound to the table? If so, just use the values of the
checkboxes to calculate the delivery charge when you print the invoice. If
the checkboxes aren't bound either, then place a textbox on the form and
bind it to the field in the table. In the AfterUpdate event of each
checkbox, you'll need to check the value of both checkboxes, calculate the
appropriate delivery charge, and place this value in the textbox. When the
record is saved, the value will be saved.
 
M

MarsGuy

As a rule don't store calculated fields in your tables.
When you design your invoice write the calculations in
the report itself. Or you can perform the calculation in
the query which populates the report (Invoice). It is
always best to avoid storing any unneccessary data or
values in your tables.>-----Original Message-----
 
G

Guest

The check boxes are bount to the table, however the code that i have used is
as follows:

If check1.Value = True Then
Text10.Value = charge.Value
Else
If check1.Value = False Then
Text10.Value = "0"
End If
End If

"Check1" is the check box, "Text10" is the delivery charge and "charge" is
the amount to charge for delivery. The value of the delivery (Text10) is
what i would like to store in the table. Any ideas??
 
J

John Vinson

The check boxes are bount to the table, however the code that i have used is
as follows:

If check1.Value = True Then
Text10.Value = charge.Value
Else
If check1.Value = False Then
Text10.Value = "0"
End If
End If

A simpler expression would be to set the Control Source of Text10 to

=IIF(Check1, [Value], 0)

No VBA code is needed at all.
"Check1" is the check box, "Text10" is the delivery charge and "charge" is
the amount to charge for delivery. The value of the delivery (Text10) is
what i would like to store in the table. Any ideas??

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox, just the same
expression as shown above for Text10.

John W. Vinson[MVP]
 

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