Hi all,
I have a function to calculated the length of time between specific dates and return results in terms of years, months, and days. This function is called in the query grid as: Length of time: Age([Start Date]) If the start date is null, it will return #error in the calculated field. How can I get rid of this and instead return a string value that states "participant not yet assigned". Below is the function:
Function Age(Appdate As Date) As String
If Appdate >= Date Then
Age = ""
Exit Function
End If
Dim intYear, intMonth, intDay As Integer
Dim curYear, curMonth, curDay As Integer
Dim difYear, difMonth, difDay As Integer
intYear = Year(Appdate)
intMonth = Month(Appdate)
intDay = Day(Appdate)
curYear = Year(Date)
curMonth = Month(Date)
curDay = Day(Date)
If intDay > curDay Then
curDay = curDay + Day(DateSerial(curYear, curMonth, 0))
curMonth = curMonth - 1
End If
difDay = curDay - intDay
If intMonth > curMonth Then
curMonth = curMonth + Month(DateSerial(curYear, curMonth, 0))
curYear = curYear - 1
End If
difMonth = curMonth - intMonth
difYear = curYear - intYear
Age = difYear & " Years, " & difMonth & " Months, " & difDay & " Days."
End Function
Thanks..
I have a function to calculated the length of time between specific dates and return results in terms of years, months, and days. This function is called in the query grid as: Length of time: Age([Start Date]) If the start date is null, it will return #error in the calculated field. How can I get rid of this and instead return a string value that states "participant not yet assigned". Below is the function:
Function Age(Appdate As Date) As String
If Appdate >= Date Then
Age = ""
Exit Function
End If
Dim intYear, intMonth, intDay As Integer
Dim curYear, curMonth, curDay As Integer
Dim difYear, difMonth, difDay As Integer
intYear = Year(Appdate)
intMonth = Month(Appdate)
intDay = Day(Appdate)
curYear = Year(Date)
curMonth = Month(Date)
curDay = Day(Date)
If intDay > curDay Then
curDay = curDay + Day(DateSerial(curYear, curMonth, 0))
curMonth = curMonth - 1
End If
difDay = curDay - intDay
If intMonth > curMonth Then
curMonth = curMonth + Month(DateSerial(curYear, curMonth, 0))
curYear = curYear - 1
End If
difMonth = curMonth - intMonth
difYear = curYear - intYear
Age = difYear & " Years, " & difMonth & " Months, " & difDay & " Days."
End Function
Thanks..