How to tell if Image control has an image

G

Gem_man

How can I use the If statement to check whether an Image control contains an
image?

I keep getting 438 error (object doesnt support proprty or method) or
Invalid Use of Object error.

I basically want to say If Image1.Picture <> Nothing then A=1

i realise that this is basic stuff but it has me stumped

Thanks in advance
Gem_man
 
K

Karl E. Peterson

Gem_man said:
How can I use the If statement to check whether an Image control
contains an image?

Interesting question. I think you can test like this:

If Image1.Picture.Handle Then
' Has image
Else
' No image
End If
 
K

Karl E. Peterson

Karl said:
Interesting question. I think you can test like this:

If Image1.Picture.Handle Then
' Has image
Else
' No image
End If

Better yet!

If Image1.Picture.Type = vbPicTypeNone Then
' No image

....
 
G

Gem_man

Hi Karl,
I am obviously overlooking the obvious somewhere. I get an "error 91 object
variable not set" with both of your suggestions.

Here is both codes that I tried
'If Image1.Picture.Type <> vbPicTypeNone Then LinkImagesWindowStatus = 1
'If Image2.Picture.Type <> vbPicTypeNone Then LinkImagesWindowStatus = 1
'If Image3.Picture.Type <> vbPicTypeNone Then LinkImagesWindowStatus = 1
'If Image4.Picture.Type <> vbPicTypeNone Then LinkImagesWindowStatus = 1

If Image1.Picture.Handle Then LinkImagesWindowStatus = 1
If Image2.Picture.Handle Then LinkImagesWindowStatus = 1
If Image3.Picture.Handle Then LinkImagesWindowStatus = 1
If Image4.Picture.Handle Then LinkImagesWindowStatus = 1

Any ideas?
 
K

Karl E. Peterson

Gem_man said:
I am obviously overlooking the obvious somewhere. I get an "error 91
object variable not set" with both of your suggestions.

No, I'm afraid I was. I tried my suggestions in VB6 before posting them.
Really shoulda done it in VBA instead. It seems the ImageX.Picture object
isn't actually instantiated until it's assigned a picture. Go figure.

This, I did test in VBA, and it seems to work just fine:

Private Sub UserForm_Click()
If Image1.Picture Is Nothing Then
Debug.Print "Empty Image"
Else
Debug.Print "Picture!"
End If
End Sub

Sorry for misleading you earlier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top