Displaying a picture on a form (referenced by name in record field)

P

Primoz Bradac

Using Access 2003 I found the following to be a greater problem than
expected.

I have a simple Employees table. One of the fields (a text field!)
contains the employee's picture filename which is a .BMP file residing
in the same directory as the .MDB file.
I want to put the employee's picture on the form (which shows also other
employee's data).

For the life of me I can't figure out :
- what control to put on the form for the picture
- what is the VBA statement to be put into the Form_Current procedure
to display the picture of the current employee.

I've tried several options but none seems to work. The latest I'm stuck
with is:

Private Sub Form_Current()
Me![Pic41].Picture = Application.CurrentProject.Path & "\" & Me![Pic]
End Sub

Pic41 is an image control and Pic is the name of text field on the form
which is bound to the correspondig field in the record
..
What I get is:

Runtime Error 2220
MS Access can't open the file ...
(the path and the file name are correct!)

I've tried With Oleobject field type in the record and Oleobject control
on the form. It worked, but I don't want to have the pictures embedded.

TIA,
Primoz
 
G

Guest

hi,
I have pictures on seveal of my forms. but i have never
changed them programaticly.
use the immage control on the tool box. to change the
picture, you must change the image control's picture
proterty to the file path of the picture.
to do what you want, i think you will have to add a column
to your employee table and put the file path of each
employees picture in it.
then when you call the employee info, change the image
controls picture property to the file path in the
employees record.
code sniplet you should add..
Dim ctlImage As Control
Set ctlImage = frm!Image1
ctlImage.Picture = employeetable.filepathfield
untested but that should get you pointed in the direction.
good luck
 
V

Van T. Dinh

It works fine in A2002 when I tested using Current Event
and an Image Control.

Did you include the file extension in the Field value?

HTH
Van T. Dinh
MVP (Access)
 
P

Primoz Bradac

Thank you Van for your answer.

Of course I didn't forget the file extension. It is a strange thing:
I stared with a new set of pictures of .JPG type and it worked. Then I
changed the original .BMP files to .JPG and changed the values in the
picture column correspondingly and it didn't work again.

Do you understand this?
The size of the .bmp files and their .jpg transformations is minimal.
The second set pictures are much bigger. I can display .bmp and the
transformed .jpg files with no problem in any picture viewer.

Primoz

It works fine in A2002 when I tested using Current Event
and an Image Control.

Did you include the file extension in the Field value?

HTH
Van T. Dinh
MVP (Access)


-----Original Message-----
Using Access 2003 I found the following to be a greater problem than
expected.

I have a simple Employees table. One of the fields (a text field!)
contains the employee's picture filename which is a .BMP file residing
in the same directory as the .MDB file.
I want to put the employee's picture on the form (which shows also other
employee's data).

For the life of me I can't figure out :
- what control to put on the form for the picture
- what is the VBA statement to be put into the Form_Current procedure
to display the picture of the current employee.

I've tried several options but none seems to work. The latest I'm stuck
with is:

Private Sub Form_Current()
Me![Pic41].Picture = Application.CurrentProject.Path & "\" & Me![Pic]
End Sub

Pic41 is an image control and Pic is the name of text field on the form
which is bound to the correspondig field in the record
..
What I get is:

Runtime Error 2220
MS Access can't open the file ...
(the path and the file name are correct!)
 
V

Van T. Dinh

Sorry, haven't heard of that problem. I never had any problem displaying
eithe JPG or BMP files.

--
HTH
Van T. Dinh
MVP (Access)


Primoz Bradac said:
Thank you Van for your answer.

Of course I didn't forget the file extension. It is a strange thing:
I stared with a new set of pictures of .JPG type and it worked. Then I
changed the original .BMP files to .JPG and changed the values in the
picture column correspondingly and it didn't work again.

Do you understand this?
The size of the .bmp files and their .jpg transformations is minimal.
The second set pictures are much bigger. I can display .bmp and the
transformed .jpg files with no problem in any picture viewer.

Primoz

It works fine in A2002 when I tested using Current Event
and an Image Control.

Did you include the file extension in the Field value?

HTH
Van T. Dinh
MVP (Access)


-----Original Message-----
Using Access 2003 I found the following to be a greater problem than
expected.

I have a simple Employees table. One of the fields (a text field!)
contains the employee's picture filename which is a .BMP file residing
in the same directory as the .MDB file.
I want to put the employee's picture on the form (which shows also other
employee's data).

For the life of me I can't figure out :
- what control to put on the form for the picture
- what is the VBA statement to be put into the Form_Current procedure
to display the picture of the current employee.

I've tried several options but none seems to work. The latest I'm stuck
with is:

Private Sub Form_Current()
Me![Pic41].Picture = Application.CurrentProject.Path & "\" & Me![Pic]
End Sub

Pic41 is an image control and Pic is the name of text field on the form
which is bound to the correspondig field in the record
..
What I get is:

Runtime Error 2220
MS Access can't open the file ...
(the path and the file name are correct!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top