Date Field and Null

  • Thread starter Thread starter Bryan Hughes
  • Start date Start date
B

Bryan Hughes

Hello,

What is the best way to check if a Date Field is null?

I have tried suing Nz and IsNull, but I keep getting Invalid use of null
error.

Please help!

-Bryan
 
IsNull should work.

Try posting the offending lines of code. There may actually be a slightly
different problem.

FWIW,

Marshall Smith
Project Developers, Inc.
 
Hi Bryan

Assuming there's not a secondary problem, the following should work well:

if len(MyDate & "")=0 then assume it's null or an empty string

The above will basically check to see if your field has got a date in it -
if it's blank, either through never having a value (null)
or having one then losing it (zero-length string) it'll pick it up.....
if you find you're having to use it lots and lots, you can always make a
function in a global module something like

checkempty(MyDate)
where "" is returned if it's empty, and the value is returned if it's not

This can be handy, especially if you then add the option of a leader and
trailer text such as ", " because you might want to use the function in a
report to display big lists of details about something, but only if there's
a value to display, like

=checkempty([forename]) & [surname] & ", " & checkempty([mobile],"mobile :
",", ") & checkempty([tel],"landline : ",", ")

The function here would be

function checkempty(inputval as variant, leadingtext as string, trailingtext
as string)
checkempty=iif(len(inputval & "")=0,"", leadingtext & inputval &
trailingtext)
end function
 
Back
Top