Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup Problem with Null

Status
Not open for further replies.

RonMcNatt

Technical User
May 22, 2002
32
US
I am using a DLookup function to check for a date in a table. I have set up this simple if-then statement to execute based on the results (I'll build a more complex if-then later).

The problem is that the DLookUp never seems to equal null so I always get the message "Date Found". If I print out the value of varX (in a MsgBox) it doesn't show any text for dates that don't exist, but I still get the "Date Found" messaage.

Any suggestions?



Dim varX as Variant

'Check to see if data already exists for date
varX = DLookup("DEL_DATE", "mTIM1", "DEL_DATE = #" & startDate & "#")
If varX = Null Then
MsgBox "The Date was not Found"
Else
MsgBox "Date Found"
End If
 
Instead of looking for Nulls, use a date that clearly won't be in your table, such as:

Dim varX as Variant

'Check to see if data already exists for date
varX = DLookup("DEL_DATE", "mTIM1", "DEL_DATE = #" & startDate & "#")
If varX < 01/01/1900 Then
MsgBox &quot;The Date was not Found&quot;
Else
MsgBox &quot;Date Found&quot;
End If
 
Try and chnage the function to this:

Dim varX as Variant

'Check to see if data already exists for date
varX = DLookup(&quot;DEL_DATE&quot;, &quot;mTIM1&quot;, &quot;DEL_DATE = #&quot; & startDate & &quot;#&quot;)
If isnull(varX) Then
MsgBox &quot;The Date was not Found&quot;
Else
MsgBox &quot;Date Found&quot;
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top