MS Access VBA-尝试提取表中的每个文件';s磁盘的附件?
我试图提取表中每条记录中包含的所有附件: 由于每条记录可能有多个附件,我想循环浏览每条记录,在磁盘上用该记录的主键创建一个文件夹,然后在该文件夹中转储属于该记录的每个附件。这是我到目前为止的代码(部分取自此处:),但它表示我的“附件”集合不存在EOFMS Access VBA-尝试提取表中的每个文件';s磁盘的附件?,vba,ms-access,Vba,Ms Access,我试图提取表中每条记录中包含的所有附件: 由于每条记录可能有多个附件,我想循环浏览每条记录,在磁盘上用该记录的主键创建一个文件夹,然后在该文件夹中转储属于该记录的每个附件。这是我到目前为止的代码(部分取自此处:),但它表示我的“附件”集合不存在EOF Dim database As DAO.database Dim table As DAO.Recordset Dim PONum As String Dim folder As String Set database = CurrentDb Se
Dim database As DAO.database
Dim table As DAO.Recordset
Dim PONum As String
Dim folder As String
Set database = CurrentDb
Set table = database.OpenRecordset("Purchasing")
With table ' For each record in table
Do Until .EOF 'exit with loop at end of table
Attachments = table.Fields("Attachments").Value 'get list of attachments
PKey = table.Fields("PKey").Value ' get record key
folder = "C:\" & PKey & "\" 'initialise folder name to create
If Len(Dir(folder, vbDirectory)) = 0 Then ' if folder does not exist then create it
MkDir (folder)
End If
' Loop through each of the record's attachments'
While Not Attachments.EOF 'exit while loop at end of record's attachments
' Save current attachment to disk in the above-defined folder.
Attachments.Fields("FileData").SaveToFile _
folder
Attachments.MoveNext 'move to next attachment
Wend
.MoveNext 'move to next record
Loop
End With
解决了。在初始化附件对象之前,我缺少“Set”:
Set Attachments = table.Fields("Attachments").Value 'get list of attachment