Picturebox is not showing the correct file

ino_mart

Registered User.
Local time
Yesterday, 18:50
Joined
Oct 7, 2009
Messages
78
All

I have a problem with a picturebox in Access 2007.

I created a table tblJPG with two fields:
Counter: an automatic incremental number which is the Primary Key
Text: some text about the picture

The effective pictures are stored in a folder JPG which is a subfolder of the location where the main access database is stored.

I created a form. The recordsource of the form is tblJPG so it shows each "counter" and "text" field stored in the table tblJPG. Until now, everything is fine.

I also put an image control on the form named imgJPG. The JPG's are named after their Primary Key. So record 1 is related with 1.jpg, record 2 is related with 2.jpg, ...

On the form, I use next code
Code:
[INDENT]Private Sub Form_Current()
Dim strY As String
strY = CurrentProject.Path & "\jpg\" & txtCounter & ".jpg"
Debug.Print strY
Me.imgJPG.Picture = strY
End Sub
[/INDENT]
txtCounter is a text field with the value of Counter of table tblJPG (so the primary key).

Access is not showing the pictures as expected. For some reason, access shows another picture. For example: if txtCounter got the value 16, Access shows the image 1.jpg (although 16.jpg does exists and is not a corrupt file). Sometimes the correct picture is shown, and other times the wrong file is shown although strY refers to the correct file.

When I create an extra (temporary) picturebox and I set the property "Picture" in the property sheet to "16.jpg", the correct file is shown.

Does somebody got an idea why this is happening and how to solve this?

Regards
Ino
 
Last edited:
It does not matter: the problem occurs with a single form and also with a continuous one.

It is some kind of bug in Access 2007 as I just figured out this issue does not occur in Access 2010. Problem is that the database must work with Access2007.
 
Two options:

1. Add Me.imgJPG.Requery at the end of your code

OR

2. Put that picture path in the record source of your form and set the control source of the image to that field.

I would go for option 2.
 

Users who are viewing this thread

Back
Top Bottom