Solved

Report with pictures from a stored folder location

Posted on 2014-07-17
2
211 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

809 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