MS ACCESS - Calc Age at Death but handle null dates
Posted on 2006-06-09
I have a function that works as long as the dates are not null but not otherwise - can you help?
If one of the dates is null I get "Invalid use of Null"
I tried putting: IF LesserDate Is not null
IF GreaterDate Is not null
(and matching End If's at the end)
but it also errors out (with Runtime '424' Object Required)
Here's the function- thanks:
Function CalcDate(LesserDate, GreaterDate) As Integer
' Returns the CalcDate in years between 2 dates
' Doesn't handle negative date ranges i.e. LesserDate > GreaterDate
If Month(GreaterDate) < Month(LesserDate) Or (Month(GreaterDate) = _
Month(LesserDate) And Day(GreaterDate) < Day(LesserDate)) Then
CalcDate = Year(GreaterDate) - Year(LesserDate) - 1
CalcDate = Year(GreaterDate) - Year(LesserDate)