[blue]Public Function AgeCalc(BirthDay As Date) As String
Dim qNow As Date, Years As Long, Months As Long
Dim rtnYears As String, rtnMonths As String
Const Yr As Integer = 12
qNow = Int(Now())
Months = DateDiff("m", BirthDay, qNow)
If (Months Mod Yr = 0) And (Day(qNow) < Day(BirthDay)) Then Months = Months - 1
[green]'If number of months is a multiple of 12, and the current day is less than the day
'of the birthday, subtract 1 month. [purple][b]This allows the birthday to change when is arrives[/b][/purple].
'LeapYear is also covered in this way![/green]
'Format Years
Years = Int(Months / Yr)
If Years = 1 Then
rtnYears = Years & "year"
ElseIf Years > 1 Then
rtnYears = Years & "years"
End If
'Format Months
Months = Months - (Years * Yr)
If Months = 1 Then
rtnMonths = Months & "month"
ElseIf Months > 1 Then
rtnMonths = Months & "months"
End If
'Determine what to return
If (rtnYears = "") And (rtnMonths = "") Then
AgeCalc = "AgeErr!"
ElseIf (rtnYears = "") And (rtnMonths <> "") Then
AgeCalc = rtnMonths
ElseIf (rtnYears <> "") And (rtnMonths = "") Then
AgeCalc = rtnYears
Else
AgeCalc = rtnYears & " " & rtnMonths
End If
End Function[/blue]