Solved Need helps with image control (1 Viewer)

Babycat

Member
Local time
Today, 15:11
Joined
Mar 31, 2020
Messages
154
Hi everyone

I have product table and form to display product detail together with product's images.
I intend to copy all product images to a folder path: CurrentProject.Path & "\DAT\Photos\" and names them same at productID, for example: The ProductID=1 will have Image names "1.jpg"
It not set, the product's image is point to "Def.jpg" what is a default image in folder "Photos"

Control source of image is set to: =[CurrentProject].[Path] & "\DAT\Photos\" & [PhotoName]

When user edit the picture, my code opens a file dialog for image selection. The selected image will be copied to folder "Photos" with name Temp.jpg.
This temp file is changed its name to "productid.jpg" only when customer click save button or close form with "saved changes".
However, this temp image should be displayed on form before user clicking Save button (this is to make a preview to selected image)

After customer select new image, i can make it show by set VBA code
Code:
Img_ProductImg.Picture = CurrentProject.Path & "\DAT\Photos\Temp." & Extension
But I can't set it back to =[CurrentProject].[Path] & "\DAT\Photos\" & [PhotoName], so that when navigating to next product, it shows same image.

I attached image of form, table Product and attached the sample db.

Please help me to take a look and advise a solution

1636576074388.png
 

Attachments

  • Example.zip
    2 MB · Views: 78

theDBguy

I’m here to help
Staff member
Local time
Today, 00:11
Joined
Oct 29, 2018
Messages
17,524
Hi. I didn't download your file, but I just had a thought. What if you add another image control behind the existing one and set it to show Temp.jpg? All you have to do is set each control visible or hidden depending on what the user is doing. In your form's Current event, you could hide the temp image control.

Would that approach work for you?
 

Babycat

Member
Local time
Today, 15:11
Joined
Mar 31, 2020
Messages
154
Hi. I didn't download your file, but I just had a thought. What if you add another image control behind the existing one and set it to show Temp.jpg? All you have to do is set each control visible or hidden depending on what the user is doing. In your form's Current event, you could hide the temp image control.

Would that approach work for you?
Yes, That is good approach work. I will try it. However, I am really afraid of overlap controls, it might causes flickering, form crash ( i have read it somewhere...), In fact, my form is currrently crashing unpredictably...
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 00:11
Joined
Oct 29, 2018
Messages
17,524
Yes, That is good approach work. I will try it. However, I am really afraid of ovelap controls, it might causes flickering, form crash ( i have read it somewhere...), In fact, my form is currrently crashing unpredictably...
I see what you mean. I suppose you could give it a try on a backup copy, so you can test it out first. Good luck!
 
Last edited:

Babycat

Member
Local time
Today, 15:11
Joined
Mar 31, 2020
Messages
154
I see what you mean. I suppose you could give it a try on a backup copy, so you can test it out first. Good luck!
I have tested, it works great.... Thank you very much!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:11
Joined
May 7, 2009
Messages
14,982
without another image control, you can add code to your form's Current Event and
reinstate the Picture to:

Me.Img_ProductImg.Picture = [CurrentProject].[Path] & "\DAT\Photos\" & [Photoname]
 

Babycat

Member
Local time
Today, 15:11
Joined
Mar 31, 2020
Messages
154
without another image control, you can add code to your form's Current Event and
reinstate the Picture to:

Me.Img_ProductImg.Picture = [CurrentProject].[Path] & "\DAT\Photos\" & [Photoname]

You are an expert... it is so simple and effficent
 

Users who are viewing this thread

Top Bottom