Error 93 - Invalid use of null

G

Guest

I have the following code:

Dim strTest As String

strTest = DLookup("[UPCFip13]", "tblPromo", "#" & dteSched & "# between " _
& "[StartDate] and [EndDate] and [UPCFip13]=" & Chr(34) & strUPC &
Chr(34))
If strTest = Null Then
IdentifyPromo = ""
Else
IdentifyPromo = "P"
End If

When dlookup doesn't fine a matching record it gives me error 93 invalid use
of null. Any ideas?
 
A

Allen Browne

Firstly you can assign a Null *only* to a variant, not to a string or any of
the number types or boolean or date or ... Your first line needs to be:
Dim varTest As Variant

Secondly nothing is ever equal to Null, so the test must be:
If IsNull(varTest) Then

For an explanation of why, see:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html
 
G

Guest

You are wonderfull. Thank you very much. Worked like magic.
--
M. Shipp


Allen Browne said:
Firstly you can assign a Null *only* to a variant, not to a string or any of
the number types or boolean or date or ... Your first line needs to be:
Dim varTest As Variant

Secondly nothing is ever equal to Null, so the test must be:
If IsNull(varTest) Then

For an explanation of why, see:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SHIPP said:
I have the following code:

Dim strTest As String

strTest = DLookup("[UPCFip13]", "tblPromo", "#" & dteSched & "# between "
_
& "[StartDate] and [EndDate] and [UPCFip13]=" & Chr(34) & strUPC &
Chr(34))
If strTest = Null Then
IdentifyPromo = ""
Else
IdentifyPromo = "P"
End If

When dlookup doesn't fine a matching record it gives me error 93 invalid
use
of null. Any ideas?
 
D

David C. Holley

The DLOOKUP() is returning NULL which cannot be assigned to a variable
dim'd as a string. Anytime that you're assigning the value from a
DLookup() to a variable, you have to either check that the value
returned ISN'T null before assigning the DLookup() result OR to declare
the variable as a Variant.
 

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