Requery Image after textbox update

brharrii

Registered User.
Local time
Today, 03:58
Joined
May 15, 2012
Messages
272
One of the fields in my database stores a path of an image that I want to display on my form. I used the following code in the "On Current" event of my form to achieve this effect:

Code:
Private Sub Form_Current()
If IsNull(Me.text1) Then
 Me.ImgPic.Picture = "C:\Users\bharr\Desktop\CupCake.jpg"
 Else
 Me.ImgPic.Picture = Me.text1
 End If
End Sub

it works great with the exception that the image doesn't update when the path is changed. If I update the path, I have to navigate to the next record and then back again in order to see the new image. I've tried a couple of things to try to requery the image after the text control is updated, but so far none have worked. This is my most recent attempt on the after update event of my text box:

Code:
Private Sub text1_AfterUpdate()
Me!ImgPic.Requery
End Sub

Does anyone know how I can refresh the image after the text box control is updated?
 
You probably need to run the same code in the textbox after update event. I'd probably make it a function and call it from both places.
 
Hmmm, I just updated the after update event of the text box and tested again but the image isn't updating until I navigate away from the record and then back to it again.
 
Can you post the db here?
 
Sure thing, here it is:

The control that stores the path has a little elipsis next that you can click on to navigate to a path on your computer to test with. I cleared out the paths I was working with since they wouldn't have worked on your computer anyways.

Let me know if you have any questions.

Thanks!
 

Attachments

Works for me when copy/pasting paths in. It doesn't work when you use the button because changing the value in code doesn't trigger the update events. You'd need the code there too, which again is why I'd use a function.
 
Oh interesting, thank you for looking at that for me.

Would I need to put the code at the end of my module then? (The code behind the button calls a module)
 
It could be in that function or you could have 2 calls:

Me!text1 = LaunchCD(Me)
RunOtherFunctionHere
 

Users who are viewing this thread

Back
Top Bottom