Placeing calculated form values into tables??

E

Em

Hi,

I have a form which calculates the difference between two user-imputted numbers (to avoid errors), but the results don't show up in the corresponding table. How can I do this?

Help!

Em
 
A

Al Camp

Em,
In most instances, you don't "save" calculations in a table.
For example, if you had fields Price and Qty, you wouldn't have to "save"
a calculation like Line Total (LineTotal=Price*Qty). Since you've captured
Price and Qty in your table,
you can always "re-derive" the LineTotal... "on the fly",
in any subsequent form/query/report/ etc...
with a calculated "unbound" field with a RecordSource of...
= Price * Qty ' I think this is what you have now

Continuing with my sample calculation and my sample field name/s... (you
correlate to your own)

If you must capture the calculation,
Add the field to your table that will hold the calculated value.
(ex. LineTotal)
Remove the calculation you have in the ControlSource of LineTotal on
the form.
"Bind" the ControlSource of LineTotal to your LineTotal field
On the AfterUpdate event for BOTH Price AND Qty fields on your
form... run this code
[LineTotal] = ([Price] * [Qty])
That way, if you enter (or change) either Price or Qty on your form your
LineTotal
field will be updated with the new calculation, and saved in your table.
--
HTH...
Al Campagna
Candia Computer Consulting
Candia, NH

Em said:
Hi,

I have a form which calculates the difference between two user-imputted
numbers (to avoid errors), but the results don't show up in the
corresponding table. How can I do this?
 
K

Ken Snell

It's usually not good practice to store a calculated value; are you sure you
really need to do this?

If yes, the field into which the value is to be stored must be part of the
form's recordsource. Then you need to run code in the form's BeforeUpdate
event to copy the value from the calculated control into this field:

Me.[FieldName] = Me.ControlName.Value

--
Ken Snell
<MS ACCESS MVP>

Em said:
Hi,

I have a form which calculates the difference between two user-imputted
numbers (to avoid errors), but the results don't show up in the
corresponding table. How 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