Date Field and Null

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
 
M

Marshall Smith

IsNull should work.

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

FWIW,

Marshall Smith
Project Developers, Inc.
 
G

Gregski.co.uk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top