Trying to add picture to a form (1 Viewer)

mjdemaris

Working on it...
Local time
Yesterday, 18:22
Joined
Jul 9, 2015
Messages
426
I see there are several threads on pictures on forms, but i am still a bit confused about how this works.
One guy mentions using LoadPicture - but MS says this is used for ActiveX image control...don't think i'm using activeX, but I tried it and got an error stating that Access could not find file 1234567890.


I have a table that stores the full file path/name, along with a file number, so PDF, pic, DOC file paths will be stored here. Each file has an ID (not the auto-incremented one).


Another table contains a field with the file ID. This is the table that the form is bound to. I would like to be able to change the picture (if needed) for the particular item that the form is displaying, so I thought a combo box would be reasonable. However, I have trouble getting the image to appear. So far, i get the same error unless I put the file path directly into the Picture property in design mode.


I think it may have something to do with the backslashes, but I'm not sure yet.


Recommendations?
Thanks.
 

June7

AWF VIP
Local time
Yesterday, 17:22
Joined
Mar 9, 2014
Messages
5,470
Images are stored external, good. Are you using an Image control and setting the image path with expression in the ControlSource property? What is that expression?

Combobox is to select an image to associate with record? Are you saving the image record ID as foreign key into this record?

What is the combobox RowSource?

Could include the image file in the form's RecordSource. JOIN type "All records from <data table> and only those from Images that match". Bind Image control to the path field from Images table.

However, PDF and DOC files cannot be displayed in Image control.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:22
Joined
Feb 28, 2001
Messages
27,167
If you have a BMP (not recommended) or JPG (recommended) file, the VBA for loading up a picture to an image control is to load the fully qualified file spec (device/path/name/type or UNC path //server/path/name/type) to the .Picture property. You should also set up the image control with regard to centering, cropping, zooming, inversion, etc.

BMP files are harder for the system to zoom & crop & stretch and other things. JPG works ok. WMF would also work if you have a picture stored that way.
 

isladogs

MVP / VIP
Local time
Today, 02:22
Joined
Jan 14, 2017
Messages
18,212
If you have a BMP (not recommended) or JPG (recommended) file, the VBA for loading up a picture to an image control is to load the fully qualified file spec (device/path/name/type or UNC path //server/path/name/type) to the .Picture property. You should also set up the image control with regard to centering, cropping, zooming, inversion, etc.

BMP files are harder for the system to zoom & crop & stretch and other things. JPG works ok. WMF would also work if you have a picture stored that way.

Interesting. I would have given different advice on file type:
BMP: good quality - but can be large file size - never had problems with resizing
JPG: not recommended - can be poor quality image in Access due to lossy format
PNG or GIF: both recommended - good quality / reasonable file size
WMF: never tried it
 

mjdemaris

Working on it...
Local time
Yesterday, 18:22
Joined
Jul 9, 2015
Messages
426
June: i am not using the ControlSource property. That property is not available in VBA.



I would like to use the combo box to select a picture, but not sure how to do it. I found out how to display the picture using dlookup, without a combo box.
 

June7

AWF VIP
Local time
Yesterday, 17:22
Joined
Mar 9, 2014
Messages
5,470
Can certainly set ControlSource property with VBA. However, my point is VBA is not needed at all.

Did you try the suggestion to include Images table in form RecordSource? Save Image ID into field. The appropriate record from Images will associate and the Image control will display the image found by the path field.
 

mjdemaris

Working on it...
Local time
Yesterday, 18:22
Joined
Jul 9, 2015
Messages
426
Currently i have the image file names in a separate table, which also includes file names for other purposes, such as safety procedures. (Side question: would this make sense to keep all external file names in one table, or should i separate them into...Pictures, Safety, etc.?)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:22
Joined
May 7, 2009
Messages
19,230
As mentioned add an Image control on the form.
Also create a Query that will link the two table so you donT need to use dlookup(). Use the query as the recordsourse of the form.
Add the field for the pics path. Make its visible prop to No if you dont want to show it.
On the Form's Current Event set the Picture property:

Private Sub Form_Current()
On Error Goto errHandler
Me.image1.Picture=Me.imagePathField
Exit Sub
ErrHandler:
Me.Image1.Picture=""
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:22
Joined
Feb 28, 2001
Messages
27,167
Ridders, you are right that a GIF works well, ditto PNG.

I've had issues with BMP files because past a certain point they get grainy or pixelated. The format for JPG is explicitly scalable as it is based on triangular regions of uniform color within the image. It is WHY a JPG is smaller than a BMP for typical portrait head shots.

A very large background area that is single-toned can be compressed into three X,Y coordinates and a color for JPG. When it comes to really complex nature scenery, the advantage might be with BMP - but it would be a VERY busy picture in that case, with no sky or water shots.
 

June7

AWF VIP
Local time
Yesterday, 17:22
Joined
Mar 9, 2014
Messages
5,470
If you use the ControlSource property instead of Picture property, no VBA. I have never used VBA to dynamically display images. Never used Picture property. Is the form in Continuous view?

Certainly can have a single table for all external files.
 

Users who are viewing this thread

Top Bottom