我想编码一个简单的任务:从Access(2013)数据库检索附件并将其保存到磁盘。此刻,我希望代码从记录集中获取第一条记录并将附件保存到C:\ maptest.pdf保存附件到硬盘
它显示错误3265:在此集合中找不到项目(但数据库中的每个记录都有一个附件)。
有没有人有一个想法我做错了什么?
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
请仔细阅读本文:[应该在标题中包含“标签”?](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles) –
行是这个错误? – RubberDuck
它显示错误:rsA.Fields(“Map”)。SaveToFile _“C:\ maptest.pdf”但当我更改“地图”到“FileData”它工作正常。似乎我不必引用名为“Map”但是“FileData”的列(即使FileData不存在作为列) – user3520938