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

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!
 
J

Jerry Porter

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
 
J

Jerry Porter

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
 
D

doodle

Adam,

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

Private Sub Lower_AfterUpdate()
Me.Difference = (Me.Higher - Me.Lower)
End Sub
 
J

Joseph Meehan

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.
 

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