Hi.
In general, you don't want to store a calculation in a table, because
information that the calculations are based upon can change, rendering the
calculated data in the table inaccurate. This can become a maintenance
nightmare trying to update all of the relevant calculations, and leads to
loss of data integrity, where some records are correct, but other records are
wrong. No one can trust the some of the data, but no one knows exactly which
data is untrustworthy.
That said, if you need to save a person's age on a specific date, say April
1, 2005, and that date isn't going to _ever_ change, you could use the
following query to set the person's age in the InsAge column in the table:
UPDATE MyTable
SET InsAge = (DateDiff("yyyy", Birthdate, #04/01/2005#) + Int("0401" <
Format(Birthdate, "mmdd")));
But it would be much better to use the following query to just display the
person's age on April 1, 2005, so if the date ever changed, only the query
need be changed, not any records:
SELECT (DateDiff("yyyy", Birthdate, #04/01/2005#) + Int("0401" <
Format(Birthdate, "mmdd"))) AS InsAge
FROM MyTable;
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. (Only "Answers" have green
check-marks.) Remember that the best answers are often given to those who
have a history of rewarding the contributors who have taken the time to
answer questions correctly.
Melisabel said:
I have a Birthdate field and an InsAge field. I want the InsAge field to
contain the calculation of the age based on the Birthdate. I used the
DateDiff formula, but only received a "O" result.
DateDiff("yyyy",[Birthdate],#04/01/2005#)+(Format([Birthdate],"mmdd")>Format
(#04/01/2005#,"mmdd"))
In a nutshell, if the birthdate field has 2/10/40, I want the InsAge field
to calculate 65. Help....