T
tina
between the birth year and the current year, as-----Original Message-----
Does anyone know how to work out the Age of someone from
a field that stores their Date of Birth and then able to
calculate whether their over a certain age using a
query. Any help would be extremely grateful
Cheers
Phill
.
the DateDiff function will tell you the number of years
DateDiff("yyyy",[DOB],Date())
but if it's important to know how old a person is TODAY,
then it will depend on whether they've had their birthday
this year or not. the following code is not elegant, but
it will do the job. save it in a public module, as
Public Function DOCalculateAge(ByRef datBirthDate As Date)
As Integer
Dim strBirthMonth As String, strBirthDay As String,
datCurrentBirthDate As Date
Dim bytAge As Byte, strPrompt As String, strReturn As
String
Dim IntYear As Integer
strBirthMonth = Month(datBirthDate)
strBirthDay = Day(datBirthDate)
IntYear = Year(datBirthDate)
If IntYear > Year(Date) Then
datBirthDate = CDate(strBirthMonth & "/" &
strBirthDay & "/" & "19" & Right(IntYear, 2))
End If
datCurrentBirthDate = CDate(strBirthMonth & "/" &
strBirthDay)
DOCalculateAge = DateDiff("yyyy", datBirthDate, Date)
If datCurrentBirthDate > Date Then
DOCalculateAge = DOCalculateAge - 1
End If
End Function
call it from the query by putting it in the query grid in
the field row, as
Age: DOCalculateAge([DOB])