Hello all,
So, I happen to be moving ~5000 documents for a project. Each one has been inserted into Microsoft Access under a column, "Attachments". Then each has been associated with a label under the column "Item#".
The objective is to write code that creates folders for each Item#, then dumps all attachments into their respective Item# folder.
I have seen code that accomplishes parts of this, but I can't yet make a complete solution.
So far I have been able to dump all files into a single folder using the following:
Anyone have thoughts on refining my method so it fits the end solution?
Thanks!!
Edit: Solution found! See my last post below if you're interested. And once again, a big thanks to all involved!
So, I happen to be moving ~5000 documents for a project. Each one has been inserted into Microsoft Access under a column, "Attachments". Then each has been associated with a label under the column "Item#".
The objective is to write code that creates folders for each Item#, then dumps all attachments into their respective Item# folder.
I have seen code that accomplishes parts of this, but I can't yet make a complete solution.
So far I have been able to dump all files into a single folder using the following:
Public Function SaveAttachmentsTest2(strPath As String, Optional strPattern As String = "*.*") As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rsA As DAO.Recordset2
Dim rsB As String
Dim fld As DAO.Field2
Dim OrdID As DAO.Field2
Dim strFullPath As String
'Get the database, recordset, and attachment field
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("database")
Set fld = rst("Attachments")
Set OrdID = rst("Item#")
'Navigate through the table
Do While Not rst.EOF
'Get the recordset for the Attachments field
Set rsA = fld.Value
rsB = OrdID.Value
'Save all attachments in the field
Do While Not rsA.EOF
If rsA("FileName") Like strPattern Then
'To Export the data, use the line below
strFullPath = strPath & "" & rsA("FileName")
'Make sure the file does not exist and save
If Dir(strFullPath) = "" Then
rsA("FileData").SaveToFile strFullPath
End If
'Increment the number of files saved
SaveAttachmentsTest = SaveAttachmentsTest + 1
End If
'Next attachment
rsA.MoveNext
Loop
rsA.Close
'Next record
rst.MoveNext
Loop
rst.Close
dbs.Close
Set fld = Nothing
Set rsA = Nothing
Set rst = Nothing
Set dbs = Nothing
End Sub
Anyone have thoughts on refining my method so it fits the end solution?
Thanks!!
Edit: Solution found! See my last post below if you're interested. And once again, a big thanks to all involved!
Last edited: