我的前同事建立了一个Access数据库,其中包含许多记录集,每个记录集都有一到五张图片。现在数据库的大小非常大(大约2 GB),并且速度很慢。
我设法将图片的路径和名称作为字符串存储在列中,而不是将图片包含在数据库附件中,然后在需要时调用它们。
现在,在重命名它们(其描述存储在数据库的另一列中)之后,我必须将所有现有图像(约3000张图片)从数据库导出到文件夹中,因为现在它们的名称就像IMG _ ####,不想在导出后手动找到并重命名它们)。
我在互联网上找到了一些东西。但是它仅导出第一个记录集的附件。我该如何修改我的需要?
Dim strPath As String
Dim rs As DAO.Recordset
Dim rsPictures As Variant
strPath = Application.CurrentProject.Path
'????How to loop through all record set???
' Instantiate the parent recordset.
Set rs = CurrentDb.OpenRecordset("Assets")
' Instantiate the child recordset.
Set rsPictures = rs.Fields("Attachments").Value
' Loop through the attachments.
While Not rsPictures.EOF
'????How to rename the picture???
' Save current attachment to disk in the "My Documents" folder.
rsPictures.Fields("FileData").SaveToFile strPath & "\Attachment"
rsPictures.MoveNext
Wend
Run Code Online (Sandbox Code Playgroud)