I have anaccess database with a table that has an OLE object field, where there isvarious type of files attached, but only one file per record.
I am trying tosave these files to different folders, but do not know how to create a VBA code,that can go through each record an save the embedded file to a folder that I define.
I´ve found somecode, but get an error in line “Set rsA = fld.Value” that it is missing anobject…
FunctionSaveAttachments()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fld As DAO.Field2
Dim strFullPath As String
'Get the database, recordset, andattachment field
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TEMP_IC_DOCUMENTS")
Set fld = rst("DOC_Attachment")
'Navigate through the table
Do While Not rst.EOF
'Get the recordset for the Attachmentsfield
Set rsA = fld.Value
'Save all attachments in the field
Do While Not rsA.EOF
MsgBox rsA("FileName")
If rsA("FileName") LikestrPattern Then
strFullPath ="e:\temp\test" & rsA("FileName")
'Make sure the file does notexist and save
If Dir(strFullPath) ="" Then
rsA("FileData").SaveToFile strFullPath
End If
'Increment the number of filessaved
SaveAttachments =SaveAttachments + 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 Function
Anyone whoknows how to do this ?