Calculated fields

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?
 
A

AlCamp

Usually, you don't save the result of a calculation!
Using this example...
If you had [Price] * [Qty] = LineTotal, you wouldn't have to save the
Line Total. As long as you save Price and Qty, you can always recalculate
LineTotal "on the fly", in any query subsequent query, form, or report.
If you must save LineTotal...
You probably already have a [LineTotal] field with =Price*Qty in the
ControlSource... (an unbound calculated field).
Remove the calculation from the ControlSource and replace it with the
LineTotal field from your table, and use the afterUpdate event of both Price
and Qty to calculate and update the [LineTotal] field.
[LineTotal] = [Price] * [Qty]
Every time Price or Qty change, LineTotal will be updated.
hth
Al Camp
 
G

Guest

I have a similar problem, however, when I change the info to the after input,
nothing shows up in the field I want calculated. The formula works now, but
I can't get the field to show up in the table or query or report. Help!

AlCamp said:
Usually, you don't save the result of a calculation!
Using this example...
If you had [Price] * [Qty] = LineTotal, you wouldn't have to save the
Line Total. As long as you save Price and Qty, you can always recalculate
LineTotal "on the fly", in any query subsequent query, form, or report.
If you must save LineTotal...
You probably already have a [LineTotal] field with =Price*Qty in the
ControlSource... (an unbound calculated field).
Remove the calculation from the ControlSource and replace it with the
LineTotal field from your table, and use the afterUpdate event of both Price
and Qty to calculate and update the [LineTotal] field.
[LineTotal] = [Price] * [Qty]
Every time Price or Qty change, LineTotal will be updated.
hth
Al Camp

Workshop said:
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?
 
A

AlCamp

Kangasroo said:
I have a similar problem, however, when I change the info to the after
input,
nothing shows up in the field I want calculated. The formula works now,
but
I can't get the field to show up in the table or query or report. Help!

AlCamp said:
Usually, you don't save the result of a calculation!
Using this example...
If you had [Price] * [Qty] = LineTotal, you wouldn't have to save the
Line Total. As long as you save Price and Qty, you can always
recalculate
LineTotal "on the fly", in any query subsequent query, form, or report.
If you must save LineTotal...
You probably already have a [LineTotal] field with =Price*Qty in the
ControlSource... (an unbound calculated field).
Remove the calculation from the ControlSource and replace it with the
LineTotal field from your table, and use the afterUpdate event of both
Price
and Qty to calculate and update the [LineTotal] field.
[LineTotal] = [Price] * [Qty]
Every time Price or Qty change, LineTotal will be updated.
hth
Al Camp

Workshop said:
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?
 
A

AlCamp

What is your calculation?
What are the your fields?
What code do you have for the AfterUpdate events of your calculation
elements?
hth
Al Camp

Kangasroo said:
I have a similar problem, however, when I change the info to the after
input,
nothing shows up in the field I want calculated. The formula works now,
but
I can't get the field to show up in the table or query or report. Help!

AlCamp said:
Usually, you don't save the result of a calculation!
Using this example...
If you had [Price] * [Qty] = LineTotal, you wouldn't have to save the
Line Total. As long as you save Price and Qty, you can always
recalculate
LineTotal "on the fly", in any query subsequent query, form, or report.
If you must save LineTotal...
You probably already have a [LineTotal] field with =Price*Qty in the
ControlSource... (an unbound calculated field).
Remove the calculation from the ControlSource and replace it with the
LineTotal field from your table, and use the afterUpdate event of both
Price
and Qty to calculate and update the [LineTotal] field.
[LineTotal] = [Price] * [Qty]
Every time Price or Qty change, LineTotal will be updated.
hth
Al Camp

Workshop said:
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?
 
J

John Vinson

I have a similar problem, however, when I change the info to the after input,
nothing shows up in the field I want calculated. The formula works now, but
I can't get the field to show up in the table or query or report. Help!

The calculated field SHOULD NOT BE STORED in any table.

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.

You can put the calculation expression in a blank field in a Query,
and then base a Form or Report on the query (rather than calculating
it in a form textbox); or, you can use the same expression on a Report
textbox as you're using on the Form.

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