invalid use of null

ellenr

Registered User.
Local time
Yesterday, 23:50
Joined
Apr 15, 2011
Messages
400
I cannot see my error. I am getting error# 94, invalid use of null with the following dlookup line:

Code:
 n1(jk) = DMin("[nettot]", "flcalc", "[fl] = " & jk & _
    " AND [tp] = " & Chr(34) & var & Chr(34) & " OR [tp] = " & Chr(34) & x & Chr(34))
    
    Dim lkup As String
    lkup = DLookup("[tp]", "flcalc", "[fl] = " & jk & " AND [nettot] = " & n1(jk))

The first line works correctly with n1(jk) = 137, so obviously [nettot] isn't null.

Any insight would be appreciated!
 
your defined lkup variable as string, so when dlookup did not find the record you are searching it will return a Null. to avoid error, concatenate the returned value from your dlookup to a null string ("").


Dim lkup As String
lkup = DLookup("[tp]", "flcalc", "[fl] = " & jk & " AND [nettot] = " & n1(jk)) & ""
 
Thanks! That fixed it and let me get beyond that point.
 
If you want a specific value set when you can't find a record, you can use the NZ function.
eg

Code:
lkup = Nz( _
     DLookup("[tp]", "flcalc", "[fl] = " & jk & " AND [nettot] = " & n1(jk)) _
     , "No record found")
 

Users who are viewing this thread

Back
Top Bottom