Solved

Report with pictures from a stored folder location

Posted on 2014-07-17
2
209 Views
Last Modified: 2014-07-27
I have a database that includes photo files that are stored not in the database but rather in a defined file folder location.

If you can imagine that you want to inventory the assets of your home.  So lets say you are Client 1 in a tbl Property table.  And you have a picture of the front of your house.  The picture file name is "1-1 House Front.JPG".   The first "1" stands for the client number, the second "1" stands for the Property ID number, and the "House Frount" part of the file name is just to represent the description of the photo.

The picture files get put into the file folder by means of clicking on a label on the property form.  The code to accomplish this is:

Private Sub lblPicturesDataPath_Click()
On Error GoTo Err_lblPicturesDataPath_Click

    Dim strAppName As String
    Dim strClientFolderName As String
    Dim strPropertyFolderName As String

    strClientFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\"
    strPropertyFolderName = TempVars!strPicturesDataPath & "\" & Trim(Me.txtClientID) & "\" & Trim(Me.txtID) & "\"
    strAppName = "explorer.exe " & strPropertyFolderName

    If Len(Dir(TempVars!strPicturesDataPath, vbDirectory)) = 0 Then
        MkDir (TempVars!strPicturesDataPath)
    End If

    If Len(Dir(strClientFolderName, vbDirectory)) = 0 Then
        MkDir (strClientFolderName)
    End If
    
    If Len(Dir(strPropertyFolderName, vbDirectory)) = 0 Then
        MkDir (strPropertyFolderName)
        MsgBox "Folder has been created on server.  Remember to place image files in this folder."
    End If

    Call Shell(strAppName, 1)

Exit_lblPicturesDataPath_Click:
    Exit Sub

Err_lblPicturesDataPath_Click:
    If Err.Number = 75 Then
        ' probably directory exists but empty
        ' ignore
        Resume Next
    Else
        MsgBox "Unexpected error " & Err.Number & " : " & Err.Description
        Resume Next
    End If

End Sub

Open in new window


Bu now I want to print the picture file on a report but do not know how to call the picture file up to print on the report.

Can anyone help?

By the way I have a setup table that includes "PicturesDataPath" as a field name.

I also have code in a module I've used before that looks like: (but I don't know if this is of any value)

Sub GettingFilesInDir(strPicturesDataPath As String, strProperty As String, strAsset As String, Optional strPictureN As String, Optional extensionStr As String = "*")

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim strFileName As String
    Dim strFullPathName As String

    Set dbs = CurrentDb

    dbs.Execute "DELETE * FROM tblAssetPics"

    Set rst = dbs.OpenRecordset("tblAssetPics")

    If Not Right(strPicturesDataPath, 1) = "\" Then strPicturesDataPath = strPicturesDataPath & "\"
    strFullPathName = strPicturesDataPath & strProperty & "\"

    strFileName = Dir(strFullPathName & "\*." & extensionStr)

    Do While strFileName <> vbNullString
        rst.AddNew
        rst.Fields("Property") = strProperty
        rst.Fields("Asset") = strAsset
        rst.Fields("PictureN") = strPictureN
        rst.Fields("PicturesDataPath") = strFullPathName & strFileName
        rst.Update
        strFileName = Dir
    Loop

    rst.Close

    dbs.Close

    Set rst = Nothing
    Set dbs = Nothing

End Sub

Open in new window

0
Comment
Question by:SteveL13
2 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 40203294
In your report:
Image control
In Detail format event.
Me!Image1.Picture = Me!ImagePath ' ImagePath holds the image path in the record source of the report

Open in new window

0
 

Author Comment

by:SteveL13
ID: 40211680
I have an image control on the report.  And in the detail format event I have:

Me!AssetImage.Picture = Me!txtPrimaryPictureFile  ' ImagePath holds the image path in the record source of the report

but I get an error:

Runtime error 2465.  DatabaseName can't find the field 'txtPrimaryPictureFile' referred to in your expression.

????
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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now