How to make a field equal to the difference of two other fields?

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

Guest

I have one field named "Higher" and another named "Lower" and another named
"difference".
The "Higher" and "Lower" fields are entered manually.
I would like for the "Difference" field to automatically be the difference
between the higher and lower fields.
Seems to be a simple problem.
Hopefully there is a simple solution.
Thanks for any help!
 
Adam,

I suggest you remove the "difference" field from your table, and
instead use a query to calculate the difference when you need it. This
would be better database design, since it would reduce the possibility
of inconsistent information occurring in your database.

Your query would include a field column with the following:
Difference:[Higher]-[Lower]

This query could be used in forms and reports.

Jerry
 
I would just use [Higher] - [Lower]

If Higher or Lower is Null, I would want Diffference to be Null. If
Difference = 0, that implies that Higher and Lower are the same.

Jerry
 
Adam,

If the "lower" field is populated last, use this:

Private Sub Lower_AfterUpdate()
Me.Difference = (Me.Higher - Me.Lower)
End Sub
 
AdamCPTD said:
I have one field named "Higher" and another named "Lower" and another
named "difference".
The "Higher" and "Lower" fields are entered manually.
I would like for the "Difference" field to automatically be the
difference between the higher and lower fields.
Seems to be a simple problem.
Hopefully there is a simple solution.
Thanks for any help!

As Jerry noted, you don't. You compute it each time you want to see it.
If you save the value into a field and one of the values changes, you would
have an invalid value. Also you would be wasting storage space and causing
Access to work harder, (retrieving the data) than it would just re-computing
it.
 
Back
Top