Hi there,
I would like to calculate a person's age in years (between 2 dates). I
am using the following function for this calculation (source:
http://www.mvps.org/access/datetime/date0001.htm)
_________________________________________
Function Age(DateOfBirth, DateToday) As Integer
' Returns the Age in years between 2 dates
If Month(DateToday) < Month(DateOfBirth) Or (Month(DateToday) =
Month(DateOfBirth) And Day(DateToday) < Day(DateOfBirth)) Then
Age = Year(DateToday) - Year(DateOfBirth) - 1
Else
Age = Year(DateToday) - Year(DateOfBirth)
End If
End Function
_________________________________________
This seems to work fine. I've one small problem though: where the
DateOfBirth field is null, a run-time error occurs, i.e. "Invalid use
of Null".
Can anyone suggest a simple way of tweaking the above function in order
to handle null values?
Any help would be greatly appreciated!
Thanks,
Stewart.