Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#error

Status
Not open for further replies.

bdm1

Programmer
Feb 4, 2002
75
US
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..
 
If isnull(Appdate) Then
Age = "participant not yet assigned"
Exit Function
End If
 
Function Age(Appdate As [!]Variant[/!]) As String
If IsNull(Appdate) Then
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top