문제

I am trying to code a simple task: retrieving an attachment from Access (2013) database and saving it to disk. At the moment I would like the code to get a first record from recordset and save the attachment to C:\maptest.pdf

It shows error 3265: Item not found in this collection (yet every record in the database has an attachment).

Does anyone have an idea what I am doing wrong?

Private Sub CommandButton4_Click()
Dim appAcc As New Access.Application
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2

Dim dbpath As String
dbpath = ThisWorkbook.Path & "\SiteDetails.accdb"

With appAcc
    .OpenCurrentDatabase dbpath
     Set rst = .CurrentDb.OpenRecordset("SiteMaps")
     Set rsA = rst.Fields("Map").Value
End With


rsA.Fields("Map").SaveToFile _"C:\maptest.pdf"


AppAcc.Quit
Set appAcc = Nothing

End Sub    
도움이 되었습니까?

해결책

It's because Map isn't the identifier DAO is using.

Change this line,

rsA.Fields("Map").SaveToFile _"C:\maptest.pdf"

to,

rsA.Fields("FileData").SaveToFile "C:\maptest.pdf"

Per Microsoft,

The FileData field is reserved internally by the Access database engine to store the binary attachment data.

Update: I posted this before I saw your latest update that you discovered the solution. To put it briefly, the reason is you're splitting a field into its own, sorta customized, child recordset of file attachments (really nice feature to have in DAO).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top