Display message when control has no image. (1 Viewer)

Thel888

New member
Local time
Today, 13:28
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 17:28
Joined
Feb 19, 2013
Messages
16,618
How are you populating the image control? Could try the controlsource property rather than the picture property
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:28
Joined
Feb 28, 2001
Messages
27,191
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.
 

June7

AWF VIP
Local time
Today, 08:28
Joined
Mar 9, 2014
Messages
5,474
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:

CJ_London

Super Moderator
Staff member
Local time
Today, 17:28
Joined
Feb 19, 2013
Messages
16,618
How would the code with the Controlsource property look like? I never used this property.
take a look at the properties for the control
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:28
Joined
May 7, 2009
Messages
19,245
Code:
If Me.photo.Picture="(none)" Then
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
end if
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:28
Joined
Sep 21, 2011
Messages
14,311
Might be better to disable the button if no picture? :(
 

moke123

AWF VIP
Local time
Today, 12:28
Joined
Jan 11, 2013
Messages
3,920
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
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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.
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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).
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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.
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:28
Joined
Sep 21, 2011
Messages
14,311
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?
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:28
Joined
Feb 28, 2001
Messages
27,191
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.

 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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?
 

LarryE

Active member
Local time
Today, 09:28
Joined
Aug 18, 2021
Messages
592
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
 

Thel888

New member
Local time
Today, 13:28
Joined
Mar 23, 2023
Messages
17
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

Top Bottom