New to VBA code and this worked PERFECTLY!
Thank you!!
__________________________________________________ _________
Re: Automatic age calculation
--------------------------------------------------------------------------------
I use this slightly longer code, but it returns the age as "15 Years 4 Months" for example.
- Option Compare Database
-
Option Explicit
-
-
Public Function fnCalculateAge(strDateOfBirth As String)
-
Dim intYears As Integer
-
Dim intMonths As Integer
-
intYears = Year(Now) - Year(strDateOfBirth)
-
If Month(Now) < Month(strDateOfBirth) Or (Month(strDateOfBirth) = Month(Now) And Day(Now) < Day(strDateOfBirth)) Then
-
intYears = intYears - 1
-
End If
-
intMonths = Month(Now) - Month(strDateOfBirth)
-
If Day(Now) < Day(strDateOfBirth) Then
-
intMonths = intMonths - 1
-
End If
-
If intMonths < 0 Then
-
intMonths = intMonths + 12
-
End If
-
fnCalculateAge = intYears & " Years " & intMonths & " Months"
-
End Function
Use as a module, and enter "=fnCalculateAge([Name of Text box with Date of Birth in])" in the text box on the form you want to display the age.
Obviously you need the Date of Birth text box on the form, but it can be invisible.
This may not be what you were looking for, but i thought id give you another option on the format of the Age calculated.
NDayave