如何将所有附件保存在MS Access表中所有记录的单个字段中?

问题描述

我正在使用Microsoft Access 2010数据库

我在一张桌子的一个字段中保存了许多图片作为附件。

如何将所有图片同时保存到本地文件夹以保存所有记录?

我需要保留附件的名称,但是它们都可以放在同一文件夹中。

谢谢:-)

解决方法

使用以下子项保存所有记录的所有附件文件。

Private Sub cmdLoadPicture_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2
Dim savePath As String

    savePath = "C:\Users\Harun.Rashid\Pictures\Screenshots\" 'Folder path to save files

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("tblEmpInfo") 'tblEmpInfo is table name
    Set fld = rst("EmpPhoto") 'EmpPhoto is Field name to table with attachment data type.

    Do While Not rst.EOF 'Loop through all records of table.
    Set rsA = fld.Value
        On Error Resume Next 'Omit errors if file already exist
        Do While Not rsA.EOF 'Loop through all attachment of single record
            rsA.Fields("FileData").SaveToFile savePath 'Save file to disk
            rsA.MoveNext
        Loop
    rst.MoveNext
    Loop

    rst.Close
    dbs.Close
Set fld = Nothing
Set rst = Nothing
Set dbs = Nothing
End Sub