Daryl and David continued the
discussion along the lines of some sort of default date to be
supplied by the programmer to make up for the fact that no
provision has been made for a null date. Later in the thread I
thought they were saying there actually IS a zero date, so I tried
(again) to test for it, and used Debug.Print to actually look at
it, but with total lack of success.
There *is* a date value of 0, and it represents 12/30/1899.
But it's not at all the same thing as Null.
An unitialized date variable has a value of 0, but that's
problematic if you are using dates that overlap that range. If
you're not, testing for 0 can be a way of knowing that the value has
not been assigned.
However, as I said in one of my responses, I would use a variant
data type for a function parameter if I were using it in a query or
recordsource that was processing data where the date fields could be
Null.
But for subs/functions *not* used in SQL statements, I would never
use a variant data type, because I wouldnt' want to pass Nulls --
I'd want the protection of the date data type automatically
rejecting a passed Null value as an error.
In other words, it depends on the context.
I do not understand how or why a null date passed to a date
variable results in something that is neither null nor zero nor
anything that Debug.Print can print,
There is no such thing as a "Null date". There are only Nulls and
dates. A Null is an unknown and while text fields in data tables and
variant variables can store a Null to represent an unknown value,
the date variable cannot (a date field in a data table *can* store a
Null, but it's an UNKNOWN).
What you get from Debug.Print depends on what you passed it. Some
functions when passed a Null will return a Null (i.e., when you pass
them an unknown, they return an unknown). Others respond
differently. You need to examine the data types accepted by a
function's parameters and its return type to know what to expect
from the function when it is passed a Null. If its date parameter is
typed as a variant, it will be able to accept a Null, and if it's
return type is typed as variant, it will be able ot return a Null.
If the data types are something else, Nulls will neither be accepted
or returned by the function. This is by design, and it's a good
thing.
Whether or not you use date data type instead of variant depends
entirely on the purpose of your function and how/where it is used.
but since it can be worked around by using a Variant type, and
since John Vinson says that this is how it should be done, I would
say that marks the end of the hunt.
It entirely depends on context, and that's why I felt it was
important to provide the details about the "road not taken" in your
particular scenario.