Display message when control has no image.

Thel888

New member
Local time
Today, 16:11
Joined
Mar 23, 2023
Messages
17
Hello friends!
I have an image type control called "photo", with no image, and a delete button on a form.

I would like when I click on the delete button to display a message like "There is no photo to be deleted!".

I already tried all these codes, one at a time, but when I click on the delete button nothing happens, although they don't give a compilation error:

Code:
If IsEmpty(Me.photo.Picture) Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if

Code:
If Me.photo.Picture = Empty Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if

Code:
If Me.photo.Picture = "" Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if

Code:
If IsNull(Me.photo.Picture) Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if

Code:
If Me.photo.Picture = Null Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if
 
How are you populating the image control? Could try the controlsource property rather than the picture property
 
I'm using the "Picture" property of the image control, for the "shared" image, so that it is stored in the form itself, because the number of entries is small, less than 100, and therefore I don't want to save photos in subfolders.

How would the code with the Controlsource property look like? I never used this property.
 
Ah, but when you have a pointer-type property (which I think .Picture is), you don't test for IS NULL, but rather IS NOTHING. Try that and see if it does the trick. The difference between IS NULL and IS NOTHING is whether the thing in question IS nothing or POINTS to nothing. Believe it or not, to VBA that distinction makes a difference.

Note also that the .picturetype property would tell you whether the picture is embedded (type = 0) or linked (type=1)

In the online documentation for an image object/control, MS does not show a .ControlSource property, perhaps because the picture is not populated by a query.
 
Image control does not have to be populated by query for ControlSource to be available. It can be unbound with expression that points to a file.

I have never used Picture property for dynamic display of images, only ControlSource.

Still not clear how you are loading this 'shared' image. Why would there not be an image and why would you delete?
 
Last edited:
How would the code with the Controlsource property look like? I never used this property.
take a look at the properties for the control
 
Code:
If Me.photo.Picture="(none)" Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if
 
Might be better to disable the button if no picture? :(
 
I use a "No Photo" image when one is not available.

Code:
me.Image0.picture = nz("Path to your photo","Path to No Photo Image")

nophoto.png
 
Image control does not have to be populated by query for ControlSource to be available. It can be unbound with expression that points to a file.

I have never used Picture property for dynamic display of images, only ControlSource.

Still not clear how you are loading this 'shared' image. Why would there not be an image and why would you delete?
Image control does not have to be populated by query for ControlSource to be available. It can be unbound with expression that points to a file.

I have never used Picture property for dynamic display of images, only ControlSource.

Still not clear how you are loading this 'shared' image. Why would there not be an image and why would you delete?
Hello again friends! Forgive me for the delay in responding.
In Office 2016 64-bit, you have three options for adding an image to an image control in the Image Type property: Embedded, Linked, and Shared. The first two I tested, but they have a disadvantage: if you move or delete the image from the source folder, the image disappears from the form control, even after being saved in the database table, in the Ole Object field. The third option, shared, which I use, keeps the image integrated into the field, as if it were an object. So I don't need to worry about creating subfolders to save these images and I don't need unlinked images, because my database is small, for a maximum of 100 clients.
 
Ah, but when you have a pointer-type property (which I think .Picture is), you don't test for IS NULL, but rather IS NOTHING. Try that and see if it does the trick. The difference between IS NULL and IS NOTHING is whether the thing in question IS nothing or POINTS to nothing. Believe it or not, to VBA that distinction makes a difference.

Note also that the .picturetype property would tell you whether the picture is embedded (type = 0) or linked (type=1)

In the online documentation for an image object/control, MS does not show a .ControlSource property, perhaps because the picture is not populated by a query.
Hello!
I tested "IsNothing" and "= Nothing", but it doesn't work, it gives an error. I believe it's because these options are native to Visual Basic but not VBA.
In Office 2016 64-bit, you have three options for adding an image to an image control in the Image Type property: Embedded, Linked, and Shared. The first two I tested, but they have a disadvantage: if you move or delete the image from the source folder, the image disappears from the form control, even after it is saved in the database table, in the Ole Object field. That's why I'm using the third option of the ".picturetype" property: Shared (type 2).
 
Might be better to disable the button if no picture? :(
If I don't find a solution, I'm seriously considering it. Or create a table to hold a blank image and point the control at it.
 
I use a "No Photo" image when one is not available.

Code:
me.Image0.picture = nz("Path to your photo","Path to No Photo Image")

View attachment 107169
If I can't find a solution, I'll do this or create a table just to store a blank image and point the image control to it.
But anyway it's a shame the VBA developers didn't think of this more clearly, because there really is a chance that you try to delete an image and the control doesn't have one.
 
But anyway it's a shame the VBA developers didn't think of this more clearly, because there really is a chance that you try to delete an image and the control doesn't have one.
That is why I suggested disabling the control? Why give the user the option when you know there is no picture?
 
That is why I suggested disabling the control? Why give the user the option when you know there is no picture?
It's an interesting option, but how to implement it if Access doesn't understand that there isn't an image inside the control?
 
Hello!
I tested "IsNothing" and "= Nothing", but it doesn't work, it gives an error. I believe it's because these options are native to Visual Basic but not VBA.
In Office 2016 64-bit, you have three options for adding an image to an image control in the Image Type property: Embedded, Linked, and Shared. The first two I tested, but they have a disadvantage: if you move or delete the image from the source folder, the image disappears from the form control, even after it is saved in the database table, in the Ole Object field. That's why I'm using the third option of the ".picturetype" property: Shared (type 2).
But one last quibble: IsNothing - as you wrote it - is one word, but the syntax is TWO words ... "IS" <space> "NOTHING" - and that syntax IS available in VBA.

 
But one last quibble: IsNothing - as you wrote it - is one word, but the syntax is TWO words ... "IS" <space> "NOTHING" - and that syntax IS available in VBA.

In mine, either the expression "Is Nothing" or "IsNothing" is giving an expression error.
Is it some reference that needs to be enabled?
 
Maybe you could test whether Me.Photo.Picture has a length or not. for example:
Code:
If Len(Me.Photo.Picture)=0 Then
    MsbBox "No Photo Is Available"
Else
    Delete the photo here
End If
 
But one last quibble: IsNothing - as you wrote it - is one word, but the syntax is TWO words ... "IS" <space> "NOTHING" - and that syntax IS available in VBA.

Now there was no error after compilation, I was putting the expression before the name of the image control!
But click and nothing happens.
 

Users who are viewing this thread

Back
Top Bottom