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

Thel888

New member
Local time
Today, 15:57
Joined
Mar 23, 2023
Messages
17
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
It gave error 438: The object does not accept the property or method.
 

moke123

AWF VIP
Local time
Today, 14:57
Joined
Jan 11, 2013
Messages
3,920
I've never used the shared or linked property of an image control . It appears that the image is saved in a deep table somewhere.
Possibly numerous times. You'd probably need to access that table to delete the photo.

Capture.PNG


Although I don't recommend attachment fields if you use one you can display the photo using the ImageAttached.FileData field and ImageAttached.FileName field to test if there's an image.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:57
Joined
Feb 19, 2013
Messages
16,616
It appears that the image is saved in a deep table somewhere

Think you will find it is saved in the MSysResources table
 

Thel888

New member
Local time
Today, 15:57
Joined
Mar 23, 2023
Messages
17
I've never used the shared or linked property of an image control . It appears that the image is saved in a deep table somewhere.
Possibly numerous times. You'd probably need to access that table to delete the photo.

View attachment 107170

Although I don't recommend attachment fields if you use one you can display the photo using the ImageAttached.FileData field and ImageAttached.FileName field to test if there's an image.
I will try this option too.
 

moke123

AWF VIP
Local time
Today, 14:57
Joined
Jan 11, 2013
Messages
3,920
Think you will find it is saved in the MSysResources table
I didn't want to poke around but knew it was in there somewhere.

Looks like it is saved as an attachment in MSysResources
 

Thel888

New member
Local time
Today, 15:57
Joined
Mar 23, 2023
Messages
17
I didn't want to poke around but knew it was in there somewhere.

Looks like it is saved as an attachment in MSysResources
Would be able to access this hidden system table and check if it is empty via VBA?
 

Thel888

New member
Local time
Today, 15:57
Joined
Mar 23, 2023
Messages
17
Finally!
I found a very practical solution and I will share it with you:

Create two picture boxes with the same size (height and width) and the following property settings:
Box 1:
Name: PhotoClient
Visible: Yes
Image Type: Shared
Image: (none)
Size Mode: Zoom
Image Alignment: Centered

Box 2:
Name: NoImage
Visible: No
Image Type: Shared
Image: *ADD ANY BLANK IMAGE HERE*
Size Mode: Zoom
Image Alignment: Centered
Note: Place this control on the same form as the other image control, in an out-of-the-way place.

Create two command buttons with the following property settings and place them just below the "PhotoClient" image box:
Button 1:
Name: ButtonAddChangePhoto

Button 2:
Name: ButtonDeletePhoto

======================================================
In the OnClick event of the ButtonAddChangePhoto button, enter this code:
Code:
Dim SearchPhoto As Office.FileDialog
Set SearchPhoto = Application.FileDialog(msoFileDialogFilePicker)

With Photo Search
    .AllowMultiSelect = False
    .Title = "Select the photo..."
    .Filters.Clear
    .Filters.Add "Customer Photo", "*.jpg; *.jpeg; *.png"

If .Show = True Then
Me.PhotoClient.Picture = .SelectedItems(1)
Else
MsgBox "No photo selected!", vbInformation, "INFORMATION"
End if
end with

Set SearchPhoto = Nothing

======================================================
In the OnClick event of the ButtonDeletePhoto button, enter this code:
Code:
If Me.PhotoClient.Picture <> Me.NoImage.Picture Then
Me.PhotoClient.Picture = Me.NoImage.Picture
MsgBox "Photo Deleted Successfully!", vbInformation, "INFORMATION"
Else
MsgBox "There are no photos to delete!", vbInformation, "INFORMATION"
End if

I sincerely thank all of you for participating in this saga!
Thanks!
 

Users who are viewing this thread

Top Bottom