I wrote a function to use in queries that takes a date and adds or
subtracts a certain length time and then returns the new value. There
are times when my function needs to return Null values.
Function DateCalc (blah...) As Variant
Do Stuff...
If Not IsNull(varNewDate) Then
DateCalc = varNewDate
End If
End Function
Then in a query - MyDate: DateCalc([Blah], [Blah], [Blah])
The results of this are in MyDate are left justified dates with a few
blank rows where the function returns a null value.
I can't filter the results on "Not Is Null", so I changed things a
bit:
MyDate: Nz(DateCalc([Blah], [Blah], [Blah]), "")
And using the criterion <> "". This seems like it will work, (I can
see the rows get populated and there are no rows with blanks), but at
the end there is an error message: Date type mismatch in criterion
expression. Then all of the cells in the results are filled with
"#Name?".
I even tried CStr(Nz(DateCalc([Blah], [Blah], [Blah]), "")), but got
the same results.
So next I changed the datatype of the funtion to Date, specified that
all the rows that would have returnd Null return "08/08/1888" (not
optimal, I know), and then running the query.
MyDate: DateCalc([Blah], [Blah], [Blah])
<>#08/08/1888#
It also looked like it would run fine, but at the end I got the same
error message about a data type mismatch in the criterion expression.
Finally, I tried querying my first query and using criterion in the
second query instead of using a criterion in my user defined function
field, but that also gave the data type mismatch error.
I don't know if it matters, but the MDB files reside on a Samba server
network.
What principles about functions and using them in queries and dealing
with Null values do I need to understand to overcome this problem?
Any suggestions?
Thanks!