Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form moving to first record on requery

Status
Not open for further replies.

kaiana

Programmer
Joined
Sep 6, 2002
Messages
85
Location
AU
I have a button on my form that inserts a photo. However after the photo is selected it isn't updated on the form. I tried me.requery but that moves to the first record. me.refresh and me.repaint doesn't work. After clicking on the insert button and selecting photo if I just move to previous or next record and then back, the photo is updated but I cannot get it to do it and stay in that record.

I am sure it is probably something basic that I am missing.

Thanks
 
kaiana,

It sounds to me that you may be attempting to embed the actual image itself into the table (via a bound control). If this is the case then, I dont think its a good idea; it makes the database LARGE and potentially unreliable.

Better idea is just to hold the filename in the table (eg. as a 50 character text field), and make this a bound field to the form. Lets call the field PhotoFileName, and give it the same Control name in the bound form.

Add a button called btnShowPicture to the form. Also add an UNBOUND image to the form; call it imgPicture. Make sure the Picture property is "(none)", and the PictureType property is "Linked"

Then, add the following code to the respective events:
[tt]
Private Sub Form_Current()
Me!ImgPicture.Picture = me!PhotoFileName
End Sub

Private Sub btnShowPicture_Click()
Me!ImgPicture.Picture = me!PhotoFileName
End Sub
[tt]

This code will load the picture into the control whenever an existing record is navigated to. It will also allow you to 'refresh' the display if a new filename is provided (via the bound text field, which should be available on the form).

Note the following:

(a) the code in the above two routines is identical
(b) I have not included any error handling; eg. if the picture file doesnt exist. Use the dir() function to check if the file exists.
(c) If you use a file naming convention, you could do this without needing a new text field; for example you could place all images in a single known folder, and name them according to the (say) unique employeeId associated with a person. Assuming an id is never re-used, this would work quite well, and would mean that the filename could be derived without the need for the extra field. All you need do is place the image in the special image folder, and make sure that its appropriately named.

hope this solves it,



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve,

Thanks for you in depth response, what you have suggested is actually what I have done. The path is saved to the table and the photo is stored in a separate folder. That is all working perfectly. The problem I am having is after selecting the location of the photo to be displayed for a particular record, it doesn't update the form (you cannot see the new photo) until you go to another record and come back, (or close the form and come back etc). me.requery takes you to the very first record, me.refresh and me.repaint don't work. This is confusing as it would appear to the data entry person that the photo has not been linked, when in fact it has, it just can't be seen straight away.

Sorry if I was not clear enough in my earlier question, hope that this has cleared it up a little.

Thanks

 
The code:

Me!ImgPicture.Picture = me!PhotoFileName

does the instant refresh for me (A2K), otherwise unsure what the problem could be.


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve,

Thanks so much, I had that code on the form current event but not at the end of the code for the button. It still didn't work but then I put a me.refresh after that and it works great.

Thanks again for your prompt reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top