howruaz9
asked on
Age Calculation
Hi experts,
I got the following from EE (pete's posting) and it worked fine until I tried to set >=18 on the criteria, the pop-up screen said: run-time error "94", Invalid use of Null, and "Age = Year(DateToday) - Year(Bdate)" was in yellow. Please help!
Function Age(Bdate, DateToday) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday
If Month(DateToday) < Month(Bdate) Or (Month(DateToday) = _
Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
Age = Year(DateToday) - Year(Bdate) - 1
Else
Age = Year(DateToday) - Year(Bdate)
End If
End Function
Save and close the module.
To use this in a query add a new column:
Age at 31-08-2003: Age([DOB],"31-Aug-2003")
Thank you!
I got the following from EE (pete's posting) and it worked fine until I tried to set >=18 on the criteria, the pop-up screen said: run-time error "94", Invalid use of Null, and "Age = Year(DateToday) - Year(Bdate)" was in yellow. Please help!
Function Age(Bdate, DateToday) As Integer
' Returns the Age in years between 2 dates
' Doesn't handle negative date ranges i.e. Bdate > DateToday
If Month(DateToday) < Month(Bdate) Or (Month(DateToday) = _
Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
Age = Year(DateToday) - Year(Bdate) - 1
Else
Age = Year(DateToday) - Year(Bdate)
End If
End Function
Save and close the module.
To use this in a query add a new column:
Age at 31-08-2003: Age([DOB],"31-Aug-2003")
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome!
/gustav
/gustav
ASKER
changes according to my situation. They are all good.
Thank you very much!