calculate age in access

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

Guest

I have created an access database where I am storing names, addresses and
date of birth. I would like to create a field showing each entries correct
age, this being calculated by using the PC clock. Is this possible and if so
how?
 
Add the function below to a module in your database, then just use
"Age([myDateofBirth]) to display the calculated current age in any
form/report.
==============================================
Function Age(varBirthDate As Variant)
Dim varAge As Variant

If IsNull(varBirthDate) Then Age = "": Exit Function

varAge = DateDiff("yyyy", varBirthDate, Now)

If Date < DateSerial(Year(Now), Month(varBirthDate), Day(varBirthDate))
Then
varAge = varAge - 1
End If
Age = varAge

End Function
=========================================
-Ed
 
I have created an access database where I am storing names, addresses and
date of birth. I would like to create a field showing each entries correct
age, this being calculated by using the PC clock. Is this possible and if so
how?

In a query:
Age: DateDiff("yyyy", [DOB], Date()) - IIF(Format([DOB], "mmdd") >
Format(Date(), "mmdd"), 1, 0)

Directly as the control source of an unbound control:
=DateDiff("yyyy",[DOB],Date())-IIf(Format([DOB],"mmdd")>Format(Date(),
"mmdd"),1,0)

You do know, I hope, that this Age computation should NOT be stored in
any table.
Just compute it and display it on a form or report, as needed.
 
OOPS. Not too accurate. A baby born in December would turn one on Jan. 1st?

--
Duane Hookom
MS Access MVP


Nikos Yannacopoulos said:
Try something like:

Age = Year(Date()) - Year([DateOfBirth])

HTH,
Nikos

KW Alexander said:
I have created an access database where I am storing names, addresses and
date of birth. I would like to create a field showing each entries correct
age, this being calculated by using the PC clock. Is this possible and
if
 
Back
Top