invalid use of null (1 Viewer)

ellenr

Registered User.
Local time
Today, 15:49
Joined
Apr 15, 2011
Messages
397
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!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:49
Joined
May 7, 2009
Messages
19,246
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)) & ""
 

ellenr

Registered User.
Local time
Today, 15:49
Joined
Apr 15, 2011
Messages
397
Thanks! That fixed it and let me get beyond that point.
 

ozinm

Human Coffee Siphon
Local time
Today, 20:49
Joined
Jul 10, 2003
Messages
121
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

Top Bottom