J
Janna
I'm would like to calculate the age a person was from a given date--not
today's date. My form name is frmEntry which has two fields called
DateScreen and DOB. I would like the following functions to calculate what
age the person was at the time of DateScreen and return the value in a third
field on my form called Age (which contains the following code =Age([DOB]) &
" yr(s) " & AgeMonths([DOB]) & " mos")
Any help is GREATLY appreciated!!--When I try the following code, it is one
year off.
Function Age(varBirthDate As Variant) As Integer
Dim varAge As Variant
If IsNull(varBirthDate) Then Age = 0: Exit Function
varAge = DateDiff("yyyy", varBirthDate, Form_frmEntry.DateScreen)
If Date < DateSerial(Year(Form_frmEntry.DateScreen), Month(varBirthDate),
Day(varBirthDate)) Then
varAge = varAge - 1
End If
Age = CInt(varAge)
End Function
Function AgeMonths(ByVal StartDate As String) As Integer
Dim tAge As Double
tAge = (DateDiff("m", StartDate, Form_frmEntry.DateScreen))
If (DatePart("d", StartDate) > DatePart("d", Form_frmEntry.DateScreen))
Then
tAge = tAge - 1
End If
If tAge < 0 Then
tAge = tAge + 1
End If
AgeMonths = CInt(tAge Mod 12)
End Function
today's date. My form name is frmEntry which has two fields called
DateScreen and DOB. I would like the following functions to calculate what
age the person was at the time of DateScreen and return the value in a third
field on my form called Age (which contains the following code =Age([DOB]) &
" yr(s) " & AgeMonths([DOB]) & " mos")
Any help is GREATLY appreciated!!--When I try the following code, it is one
year off.
Function Age(varBirthDate As Variant) As Integer
Dim varAge As Variant
If IsNull(varBirthDate) Then Age = 0: Exit Function
varAge = DateDiff("yyyy", varBirthDate, Form_frmEntry.DateScreen)
If Date < DateSerial(Year(Form_frmEntry.DateScreen), Month(varBirthDate),
Day(varBirthDate)) Then
varAge = varAge - 1
End If
Age = CInt(varAge)
End Function
Function AgeMonths(ByVal StartDate As String) As Integer
Dim tAge As Double
tAge = (DateDiff("m", StartDate, Form_frmEntry.DateScreen))
If (DatePart("d", StartDate) > DatePart("d", Form_frmEntry.DateScreen))
Then
tAge = tAge - 1
End If
If tAge < 0 Then
tAge = tAge + 1
End If
AgeMonths = CInt(tAge Mod 12)
End Function