Solved

Need to display JPEG Images in Forms and Reports - MS Access  - from photo file folder

Posted on 2011-02-28
14
1,352 Views
Last Modified: 2012-05-11
I have a 2003 Access database for tools.  Besides the tool description, serial number, etc., I have a photo for each tool in a separate directory.  The photos are saved by using the same [ToolName] that is in the database.  I also have a [FolderPath] field.  So, I need a way to display the JPEG using the [FolderPath] & [ToolName] in a Form and Report.  

Bitmaps are not acceptable, so I don't want to imbed a bitmap into an OLE Object field.  I also don't want to bloat the database with images.
0
Comment
Question by:jmar6729
  • 5
  • 3
  • 3
  • +2
14 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34999351
A couple of issues before going any further...

Access does not have a native jpeg viewer.
Therefore you must have a viewer installed on your pc with the relevant file associations set.

Also, standard Access will only allow you to view  one image at a time when it is fetched from an external source, no matter how many records you are displaying (all records show the same image at any time).  
If you want to show different images on different records in a continuous form then to do that you will need a third-party add-in.  You can try DBPix for that and it will also solve the first issue as well.
0
 
LVL 7

Expert Comment

by:shaydie
ID: 34999550
You can add an image control to your form or report and with code to set the path of the picture.

Something like below

Form:
Private Sub Form_Current()
foldername = me.folderpath
pic = me.toolname
Me.Image1.Picture = foldername & pic
End Sub

(Also don't forget to add an additional "/" inbetween path and file if the slash doesn't already exist in the foldername field.

Report:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
foldername = Me.FolderPath
pic = Me.ToolName
Me.Image1.Picture = foldername & "\" & pic
End Sub
0
 

Author Comment

by:jmar6729
ID: 34999624
Well, that explains a lot.  Glad I asked the question before I wasted more time.

You are correct that I want different images for each record on a continuous form.

Do you know if Access 2010 will allow me to do what I want without an add-in?  
0
 
LVL 7

Expert Comment

by:shaydie
ID: 34999676
I'm pretty sure it will.. You can do it with access 2007 so I would assume 2010, If you have a field with the full path name of the pictures.. You add an image control and set the control source of the image control to the field that contains the path to the picture.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35001097
Just FYI.

Even though the images are linked, some bloating will occur.
This is because Access must create a temp bitmap in order to display the image.

So be sure to run the compact/repair utility on a regular basis...
0
 

Author Comment

by:jmar6729
ID: 35002160
I've tried a few variations, including hard-coding the jpg picture path and name but when I open the form I get a dialog box that says Access can't open the file.

Run-time error '2220':
Microsoft Office Access can't open the file '...drill.jpg'.

Private Sub Form_Current()
Dim strFolderName
Dim strPic
   
strFolderName = Me.PhotoPath
strPic = Me.Photo_Name
'Me.Image53.Picture = (I put path here)/drill.jpeg
Me.Image53.Picture = strFolderName & strPic & ".jpg*"

End Sub
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35003491
<Access does not have a native jpeg viewer.>  Beg to differ.  Set the Current event of an Image on a form with hyperlinks to a folder/file as follows:

Private Sub Form_Current()
  Me!imgRTWPics.Picture = HyperlinkPart(Me!MyHyperlink, acAddress)
End Sub

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35003598
Here is what I use.

See if it works in your environment.
If it does not, then perhaps this is a file association issue.
Access-BasicLinkFormReportImages.mdb
0
 

Author Comment

by:jmar6729
ID: 35008547
GrayL: I got the Jpegs to work on a form.  Thanks. Using hyperlinks fits into my application very well.

I also have a need to have them on a report.  Do you have a way to do that also?
0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 35008780
Create a query to give you just the pictures you want for a particular report.  Base the report on that query, rather than the whole table.  Then I believe you can use the OnFormat event of the Detail section to store the code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Me!imgRTWPics.Picture = HyperlinkPart(Me!MyHyperlink, acAddress)
End Sub
0
 

Author Comment

by:jmar6729
ID: 35009440
shaydie:  I just could not get that script to work for me.  The hyperlink solution that GrayL offered is best for me, since I already created hyperlinks from database fields.

boag2000: Sorry I could not get your mdb to open.  I wish security programs would stop treating Access macros and VBAs as malignant viruses.

0
 

Author Closing Comment

by:jmar6729
ID: 35009481
This was a perfect solution for me since I already have the hyperlinks or each record.  The script was very minimal also which is wonderful. Thanks a lot.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35009670
<boag2000: Sorry I could not get your mdb to open. >
No worries.

As long as you have a solution, I'm happy.

Jeff
0
 
LVL 44

Expert Comment

by:GRayL
ID: 35012841
Thanks a lot, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access creating a Chart from Search result on Form view 2 21
Direct Mail software 4 45
Format Meeting Request through VBA 5 21
Query design issue 2 24
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now