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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup getting Run time error '94' Invalid use of nulls

Status
Not open for further replies.

smsmail

Programmer
Aug 11, 2010
105
US
Hi

I am getting a run time error on the dlookup code, because no record meet the criteria, therefore the dlookup returned a null value.

Code:
Dim lngLogID As Long
    
    lngLogID = DLookup("[LogID]", "Download_Log", "[JobNumber] = '" & Me.JobNumber & "' and [ClientID]= " & Me.clientid)
      
    Debug.Print lngLogID
    
    If Not IsNull(lngLogID) Then
       DoCmd.OpenForm "frmdownloadlog", , , "logid = " & lngLogID, acEdit
    Else
       DoCmd.OpenForm "frmdownloadlog", , , , acEdit
    End If

[code/]

Is there a simple way of handling this?

Thanks for your help
 
dlookup returns a Null if not found. You cannot assign a long variable to null

Dim lngLogID As variant

 
you can also wrap the dlookup in a null to zero (NZ) function

lngLogID = NZ(DLookup("[LogID]", "Download_Log", "[JobNumber] = '" & Me.JobNumber & "' and [ClientID]= " & Me.clientid),0)
...
If lngLogID <> 0 Then
 
Thanks MajP. Your help is very much appreciated~!

 
FYI
Access Help file said:
Although criteria is an optional argument, if you don't supply a value for criteria, the DLookup function returns a random value in the domain.

If no record satisfies criteria or if domain contains no records, the DLookup function returns a Null.

If more than one field meets criteria, the DLookup function returns the first occurrence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top