Solved Invalid Use of Null Error 94 (1 Viewer)

PatAccess

Registered User.
Local time
Today, 00:46
Joined
May 24, 2017
Messages
284
Hello Guys,
Why am I getting an error with this code? Some of the records do not have an image file path. How can I handle this?
Code:
    Dim strImageSQL As String
    Dim strImage As String
    strImageSQL = "SELECT [Image] FROM QrySuppliesDetails WHERE SupplyDetailID=" & Me.lstDetails.Column(0) & ""
    strImage = CurrentDb.OpenRecordset(strImageSQL).Fields(0).Value
    If IsNull(strImage) Then
        Me.Image38.Picture = ""
    Else
        Me.Image38.Picture = strImage
    End If
Thank you
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:46
Joined
Mar 14, 2017
Messages
8,777
Another possibility is that

Me.lstDetails.Column(0)

.... resolves to Null, at run-time. Check first:

Code:
If Me.lstDetails.ItemsSelected.Count>0 then
...Code Continues
End If

Or

Code:
If Not IsNull(Me.lstDetails) then
...Code Continues
End If
 

PatAccess

Registered User.
Local time
Today, 00:46
Joined
May 24, 2017
Messages
284
Thank you Guys. declaring my variable as variant and pre-checking worked.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:46
Joined
May 7, 2009
Messages
19,229
without Any pre-checking, you can modify your code:
Code:
     Me.Image38.Picture = DLookup("Image","QrySuppliesDetails","SupplyDetailID=" & Nz(Me.lstDetails, -1)) & ""
much compact.
 

Users who are viewing this thread

Top Bottom