Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / February 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rodz - 09 Feb 2006 14:28 GMT
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.
Rick B - 09 Feb 2006 14:32 GMT
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".

Signature

Rick B

> 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.
Keith Wilby - 09 Feb 2006 14:50 GMT
> 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
John Spencer - 09 Feb 2006 17:04 GMT
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") )

> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.