Oct 19th, 2000, 12:42 AM
I am trying to use that function to calculate the age of a person in years, months, and days. I typed this function in a module and would want the result based on Date of Birth displayed in a text box on a form. MY PROBLEM IS ON HOW TO HAVE THE RESULT RESULT DISPLAYED IN A TEXT BOX. I entered the aSns=yer & "years"& mon &"month(s)"& d &"day(s) old." expression in the controlsouse property but unfortunately I am getting a #Name error in the text box. Can someone help me with how how best I can end up with the age in the text box.
Public Function ExactAge(Date_of_Birth As Variant) As String
Dim yer As Integer, mon As Integer, d As Integer
Dim dt As Date
Dim sAns As String
If Not IsDate(Date_of_Birth) Then Exit Function
dt = CDate(Date_of_Birth)
If dt > Now Then Exit Function
yer = Year(dt)
mon = Month(dt)
d = Day(dt)
yer = Year(Date) - yer
mon = Month(Date) - mon
d = Day(Date) - d
If Sgn(d) = -1 Then
d = 30 - Abs(d)
mon = mon - 1
End If
If Sgn(mon) = -1 Then
mon = 12 - Abs(mon)
yer = yer - 1
End If
sAns = yer & " year(s) " & mon & " month(s) " & d _
& " day(s) old."
ExactAge = sAns
End Function
Public Function ExactAge(Date_of_Birth As Variant) As String
Dim yer As Integer, mon As Integer, d As Integer
Dim dt As Date
Dim sAns As String
If Not IsDate(Date_of_Birth) Then Exit Function
dt = CDate(Date_of_Birth)
If dt > Now Then Exit Function
yer = Year(dt)
mon = Month(dt)
d = Day(dt)
yer = Year(Date) - yer
mon = Month(Date) - mon
d = Day(Date) - d
If Sgn(d) = -1 Then
d = 30 - Abs(d)
mon = mon - 1
End If
If Sgn(mon) = -1 Then
mon = 12 - Abs(mon)
yer = yer - 1
End If
sAns = yer & " year(s) " & mon & " month(s) " & d _
& " day(s) old."
ExactAge = sAns
End Function