MS-Access VBA-试图将表附件中的每个文件提取到磁盘吗? [英] MS-Access VBA - Trying to extract each file in a table's attachments to disk?

查看:399
本文介绍了MS-Access VBA-试图将表附件中的每个文件提取到磁盘吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提取表中每个记录中包含的所有附件:

I'm trying to extract all the attachments contained within each record in a table:

由于每个记录可能具有多个附件,因此我想遍历每个记录,使用该记录的主键在磁盘上创建一个文件夹,然后将属于该记录的每个附件转储到该文件夹​​中.这是我到目前为止的代码(部分摘自此处: https://msdn.microsoft.com/zh-CN/library/office/ff835669.aspx ),但这是说我的附件"系列不存在EOF.

As each record may have multiple attachments, I would like to loop through each record, creating a folder on disk with that record's primary key, and then dump each attachment belonging to that record, in that folder. This is the code I have so far (Partly taken from here: https://msdn.microsoft.com/en-us/library/office/ff835669.aspx) but it's saying EOF doesn't exist for my 'Attachments' collection.

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

推荐答案

已解决.在初始化附件对象之前,我缺少设置":

Solved it. I was missing the "Set" before I initialised my Attachments object:

Set Attachments = table.Fields("Attachments").Value 'get list of attachment

这篇关于MS-Access VBA-试图将表附件中的每个文件提取到磁盘吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆