Best practise for Dlookup hitting a null?

  • Thread starter Thread starter Laurel
  • Start date Start date
L

Laurel

I was surprised to find that DLookup returns an error if the data being
looked up is null. What does one do about this - what if you want to find
out if the data is null? How do you prevent an error?
 
Laurel said:
I was surprised to find that DLookup returns an error if the data being looked
up is null. What does one do about this - what if you want to find out if the
data is null? How do you prevent an error?

You are incorrect. Dlookup() is perfectly happy to return a Null and does so
without generating an error. Most likely you tried to set the value of a
non-Variant variable with a Dlookup() statement that returned Null and THAT
(assigning a non-Variant variable to Null) is what causes an error.

If there is a possibility that your Dlookup will return Null then either use a
Variant variable type or wrap the Dlookup() in the Nz() function so that the
Null is replaced with some other acceptable value.
 
Back
Top