L
lcox400w
I am using Allen Browne's date function I got from another posting. I am
trying to get it to work. I need to comepare the persons DOB from the date
an incident occurred "DateOccd". I get a #Name? when I look at the age field
using the below formula. I know the problme is in the control source as if I
use a fixed date it works fine, just doesnt work when I put inthe "DateOccd"
field. Not sure hwo to list that.
In the control source I have put:
=Age([DOB],[Me.Parent!DateOccd])
The Allen Browne's funciton is:
Function Age(varDOB As Variant, Optional varAsOf As Variant) As Variant
'Purpose: Return the Age in years.
'Arguments: varDOB = Date Of Birth
' varAsOf = the date to calculate the age at, or today if
missing.
'Return: Whole number of years.
'To use this function, put a text box on your form and sets its
controlsource
'to =Age([BirthDate], #09/21/08#)
Dim dtDOB As Date
Dim dtAsOf As Date
Dim dtBDay As Date 'Birthday in the year of calculation.
Age = Null 'Initialize to Null
'Validate parameters
If IsDate(varDOB) Then
dtDOB = varDOB
If Not IsDate(varAsOf) Then 'Date to calculate age from.
dtAsOf = Date
Else
dtAsOf = varAsOf
End If
If dtAsOf >= dtDOB Then 'Calculate only if it's after person
was born.
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
Age = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
End If
End If
End Function
trying to get it to work. I need to comepare the persons DOB from the date
an incident occurred "DateOccd". I get a #Name? when I look at the age field
using the below formula. I know the problme is in the control source as if I
use a fixed date it works fine, just doesnt work when I put inthe "DateOccd"
field. Not sure hwo to list that.
In the control source I have put:
=Age([DOB],[Me.Parent!DateOccd])
The Allen Browne's funciton is:
Function Age(varDOB As Variant, Optional varAsOf As Variant) As Variant
'Purpose: Return the Age in years.
'Arguments: varDOB = Date Of Birth
' varAsOf = the date to calculate the age at, or today if
missing.
'Return: Whole number of years.
'To use this function, put a text box on your form and sets its
controlsource
'to =Age([BirthDate], #09/21/08#)
Dim dtDOB As Date
Dim dtAsOf As Date
Dim dtBDay As Date 'Birthday in the year of calculation.
Age = Null 'Initialize to Null
'Validate parameters
If IsDate(varDOB) Then
dtDOB = varDOB
If Not IsDate(varAsOf) Then 'Date to calculate age from.
dtAsOf = Date
Else
dtAsOf = varAsOf
End If
If dtAsOf >= dtDOB Then 'Calculate only if it's after person
was born.
dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
Age = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
End If
End If
End Function