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!

Function getting error when field empty

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
I have a function(below) I use in a query. The inputs are from other fields, but if the number field is empty, I get an "error#" as output(I need it empty). Any ideas on how to fix this.


Function nextdate(Optional firstdate As Date, Optional intervaltype As String, Optional number As Integer = 0) As Date
On Error GoTo handle

If number = 0 or ismissing(number) or isempty(number) or isnull(number) Then
nextdate = Empty

Exit Function
Else
Dim mydate As String
Dim myday

If LCase(intervaltype) = "m-f" Then
myday = LCase(WeekdayName(Weekday(firstdate)))

If myday = "friday" Then
nextdate = DateAdd("d", 3, firstdate)
Exit Function
Else
nextdate = DateAdd("d", 1, firstdate)
Exit Function
End If

ElseIf number > 0 Then
mydate = Format(firstdate, "m/d/yyyy")
nextdate = DateAdd(intervaltype, number, mydate)
Else
nextdate = Empty

End If

Exit Function
End If

handle:
msgbox Err.Description

End Function
 
Just a quick thought (a very quick thought) -- can you set your variable to "null" instead of empty?

If number = 0 or ismissing(number) or isempty(number) or isnull(number) Then nextdate = Null

If I think of this any more I'll send you back more thoughts.

PA


 
I think you need to return a variant from your function, as otherwise it is expecting a date variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top