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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Photo of Recipe in Form

Status
Not open for further replies.

Bill6868

Technical User
Mar 20, 2007
96
US
I have a recipe database and would like a picture of the recipe to show up on my form when it opens. I'd like to store the picture in the table itself. I trird using an OLE Object data type as a field in my table but when I insert the .jpg the picture does not show up - only the file name of the picture. I have to double-click the file name and the photo opens up in MS Picture Manager. I'd also like the picture to show up on the report so when I print the recipe the photo prints also.

Any suggestions would be most appreciated.

 
What version of Access are you using? 2007 is much more capable then prior versions and solves the database bloat issue. It has lots of ways to do this.
If using a version prior to 2007 then state about how many photos you plan to store. Prior to 2007 Access was very inefficient and there is a feasible amount that you can really store internally.
 
I'm using Access 2007. I created a field in my table called photo - the data type is "attachment". This solved my problem. However the size limits of Access is always a consideration. I understand that Access 20077 can grow to 2GB. Is this true? If so, I'd like to continue with adding pictures. Perhaps I can take them into Picture Manager first and comnpress them before I insert into my Access field.

Thanks for your comments.
 
Access 2007 makes it super easy to store all your pictures in a folder, and then have them render on a form or report. This use to be difficult to do. So if you want to store them in a folder then you are limited to the size or your hard-drive. You can use the file browser and a little code to save the file name into you database. One trick is to save only the file name and not the path. Then if you move the folder to somewhere else you just save the location of the folder and recalculate new paths on the fly.

With the attachment datatype you can likely store more than 2g of data because it compresses the attachment. With that said I do not think a JPG compresses any further. Reducing the image size however would be different then compressing.
Some Attachment Info:
- The maximum size of an attached data piece cannot be larger than 256Mb
- Adding, deleting, and editing of the attached items is only possible through an Attachments dialog box.
- In the design of Forms and Reports there is new item in the toolbox: the Attachment control (looks like a paper clip). This control may be used at design time.
- Editing an attachment is possible if the program used for creating the attachment is available on the local computer. The program will edit the attachment and when it is saved the attachment gets saved to its own field.
- Access will compress uncompressed files in the attachments before storing them.
- Attachments may originate from any location on the disk drive or the network.
- VBA can be used to work with attachments programmatically using the new Attachment Object. It has several properties and methods, and it supports event

Bottom line in Access 2007 you can efficiently put in a whole lot of images using the attachment field. Depending on the size of your DB it is probably good up to around 2G of image data. You can easily work with images in a seperate folder without size limit. And even OLE fields use compression now and are far more efficient.
 
I used this for years. works in Access '97 thru 2010? I just now checked it in 2010. this loads images when you navigate back and forth or anytime you are on the a current record.
See FAQ on tek-tips faq181-279
I originally wrote the FAQ back in the year 2000 but used it for a few years prior.
Code:
Add an "Image" control to the form. and make the picture type property linked not embedded. you might have to load an image to get a image control on the form.  but when you clicked linked in 2010 in the picture type property it says do you want to delete it? then click YES, you do not want an image in the control or it will not change when the current event fires.
this code goes in the on-current event of the form. This assumes the photo name is the ID field. such as 1234.jpg
I have also used a another field with the image name in it like MyPhoto.jpg where as the code would be:
Me!Image14.Picture = "c:\yourfolder\Photosfolder\" & me![AnyFieldNameHere] & ".jpg"
[code]
Private Sub Form_Current()
    If Me![ID] <> 0 Then
        Me!Image14.Picture = "c:\yourfolder\Photosfolder\" & Me![ID] & ".jpg"
'this is if you want to see the folder location on the form        
Label20.Caption = "File: " & " c:\yourfolder\Photosfolder\" & Me![ID] & ".jpg"
    End If
       
End Sub

Note: it can be bit slow if the pictures are very large and they are drug across the network.

Hope this helps Happy Holidays ;) [xmastree] [starofdavid] [frosty2][frosty]


DougP
 
Doug,
As I pointed out there is absolutely no reason to do that anymore unless you need backwards compatibility to 2003 and older. The new features are easier to use, more flexible, and provide more features. You would simply bind the bound image control to the field with a path and it would render the image. No code required. And the new control would work in a continuous form and yours does not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top