How do I calculate ages in a simple table in Access?

G

Guest

My table is simple. Field names are Last Name, First Name, Birthdate, Age. I
would like it to calculate the age when I enter the birthdate.
 
R

Rick B

You don't. You can't store a moving target in a table.

The correct method is to calculate age (as of the current date) in your
queries, forms, and reports.

The proper formula is:

DateDiff("yyyy",[Birthdate],Date())+(Format([Birthdate],"mmdd")>Format(Date(),"mmdd"))



For more details, read the previous posts on "calculated fields" or
"calculating age".
 
K

Keith Wilby

Rodz said:
My table is simple. Field names are Last Name, First Name, Birthdate, Age.
I
would like it to calculate the age when I enter the birthdate.

You would calculate the age in a query at run-time. You would not usually
store a calculation so your Age field is redundant. Look up "calculated
fields" and "DateDiff" in the help - you'd need to find the difference
between the system date (using the "Date() function") and the stored date
and then express it in the format of your choice.

You'd also need to handle nulls in the DOB field so you don't get run-time
errors.

Regards,
Keith.
www.keithwilby.com
 
J

John Spencer

As others have mentioned you USUALLY don't store the age. However, if you
need the age as of the date of entry, then you either need to store the date
of entry (and use it to calculate the age when you need the age) or you do
need to store the age.

The only way that Access will populate a field with a calculation is through
a form. Are you using a form for data entry? Normally, you should be.

The formula for calculating age (in years) is
DateDiff("yyyy", [Bdate], Date())+ Int( Format(Date(), "mmdd") < Format(
[Bdate], "mmdd") )
 

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