Display all attached files in a report (1 Viewer)

Ole

Registered User.
Local time
Today, 11:55
Joined
Apr 15, 2012
Messages
32
Hi

I'm creating a report in which I want to display all attached files for each record.
My problem is that the report only display the first file instead of all the files.

What am I missing here?

/Ole
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:55
Joined
Oct 29, 2018
Messages
21,471
Maybe try using a subreport for the attached files?
 

Micron

AWF VIP
Local time
Today, 05:55
Joined
Oct 20, 2018
Messages
3,478
Many of us here do not use attachment fields, but that is another story perhaps. As a result, I have to ask, you can actually have multiple attachments for any record? I would not have thought so but that is how your question reads.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:55
Joined
May 7, 2009
Messages
19,241
if all your Attachments are Images (pictures), then use a Query as recordsource of your report:

select field1, attachmentFieldName.Filename as Filename from yourTable;

on your report, remove the attachment control and put an Image Control.

add code to Detail section (Format event) of report:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim d As DAO.Database
    Dim a As DAO.Recordset2
    Dim b As DAO.Recordset2
    Dim p As String
    
    p = Environ("temp") & "\" & [FileName]
    Set d = CurrentDb
    Set a = d.OpenRecordset("select * from tblAttachment where id=" & [ID] & ";")
    Set b = a.Fields("attachmentFieldNameHere").Value
    With b
        .MoveFirst
        While .Fields("Filename") <> [FileName]
            .MoveNext
        Wend
        If Dir(p) <> "" Then Kill p
        .Fields("FileData").SaveToFile p
    End With
    Set b = Nothing
    Set a = Nothing
    Set d = Nothing
    [yourImageControl].Picture = p
End Sub
 

Users who are viewing this thread

Top Bottom