Update Images With Command Button

miscnine

New member
Local time
Today, 14:54
Joined
Jun 14, 2002
Messages
9
I just need a little help on adding a feature to my forms.

I have a text box called "filelocation", and an image that is set to update when "filelocation" is updated. I have that working fine when I just type in the location of the file. I just added a command button to browse files so that the user doesn't have to type in the location everytime. However (here's my problem), I cannot get the text box to accept the file name, it tells me the text box is not big enough to paste the information into (even though the box is set at 255 char). So if I set the command button to paste in an unbound text box, it works fine; except now I cannot store the file location and the image won't update after I choose a file.

I have read through several post here, and found great information, but not enough to get me past this hurdle. If anyone has code or just some helpful tips, I would greatly appreciate it.
 
Found My Answer

After doing several more searches, and trying out some code, I came across my answer. It may be more than what is needed, but it gets the job done.

I went to Microsoft's Knowledge base and followed the directions for Q303066 (this gives you a command button that opens the window to browse files). I made the textbox text1 un-enabled and locked, and made the colors blend in with the background so that users could not see it and mess with it. I then added the following code to the commandbutton after click event, after the Me!Text1 = LaunchCD(Me):

Me!Text1.SetFocus
DoCmd.RunCommand acCmdCopy

Me!ImageLocation.SetFocus
DoCmd.RunCommand acCmdPaste

(Where ImageLocation is the textbox you want to store your image file location)

(This cuts the information form text1 and puts it in the ImageLocation textbox)
---

Then, on the form you are using, make the event On Current as follows:

Private Sub Form_Current()

On Error Resume Next

Me![Image].Picture = Me![ImageLocation]

End Sub

(Where [Image] is your Unbound Image on your form, and [ImageLocation] is your textbox where the image will update from)

---

Then, On ImageLocation, make the AfterUpdate event as follows:

Private Sub ImageLocation_AfterUpdate()

On Error Resume Next

Me![Image].Picture = Me![ImageLocation]

End Sub

---

That is all. Once I select a file from the window and move to the next field, the image updates. If you have any questions, please email me, and put in the subject line AC2K, so I know to read it. If you have any suggestions, I would like to know how to make this better, and less complex.

miscnine@hotmail.com
 
Correction

leave text1 enabled, otherwise it will not update. I forgot that I had to change this. You can lock the textbox still.

miscnine@hotmail.com
 

Users who are viewing this thread

Back
Top Bottom