Solved

Report with pictures from a stored folder location

Posted on 2014-07-17
2
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

717 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