|
楼主 |
发表于 2021-3-16 22:57
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
zpy2 发表于 2021-3-16 04:10
Public Function LoadAttachments(strPath As String, Optional strPattern As String = "*.*") As Long Di ...
是这个意思么,大佬
Public Function LoadAttachments(strPath As String, Optional strPattern As String = "*.*") As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2
Dim strFile As String
'Get the database, recordset, and attachment field
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblAttachments")
Set fld = rst("Attachments")
'Navigate through the table
Do While Not rst.EOF
'Get the recordset for the Attachments field
Set rsA = fld.Value
'Load all attachments in the specified directory
strFile = Dir(strPath & "\*.*")
rst.Edit
Do While Len(strFile) > 0
'Add a new attachment that matches the pattern.
'Pass "" to match all files.
If strFile Like strPattern Then
rsA.AddNew
rsA("FileData").LoadFromFile strPath & "\" & strFile
rsA.Update
'Increment the number of files added
LoadAttachments = LoadAttachments + 1
End If
strFile = Dir
Loop
rsA.Close
rst.Update
'Next record
rst.MoveNext
Loop
rst.Close
dbs.Close
Set fld = Nothing
Set rsA = Nothing
Set rst = Nothing
Set dbs = Nothing
End Function |
|