Solved

Report with pictures from a stored folder location

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

16 Experts available now in Live!

Get 1:1 Help Now