Public Sub CopyAccessAttsToAccess(rstSourceAttachments _
As DAO.Recordset2, rstTargetAttachments _
As DAO.Recordset2)
‘Called from CreateDenormalizedContactsTable,
‘UpdateAllAccessContacts, UpdateOutlookContactID,
‘UpdateAccessContactID, UpdateOutlookContactName,
‘UpdateAccessContactName, UpdateAllAccessContacts,
‘UpdateOutlookContactID, cboAttachments_Click on
‘fsubCopyFieldDataOn Error GoTo ErrorHandlerSet fso = CreateObject(“Scripting.FileSystemObject”)Do While Not rstSourceAttachments.EOFNeed to extract the file name from the FileName field, using the SplitFileName function, because it
sometimes contains the path (sometimes multiple times) as well as the file name.strFile = _SplitFileName(rstSourceAttachments.Fields(“FileName”))
Debug.Print “File name: “ & strFile
strFileAndPath = strDocsPath & strFile
Debug.Print “File and path: “ & strFileAndPathOn Error Resume NextCheck whether this file already exists in the folder, and save it to the folder if not.Set fil = fso.GetFile(strFileAndPath)
If fil Is Nothing ThenSave this attachment to a file in the Output Docs folder.rstSourceAttachments.Fields(“FileData”).SaveToFile _
strFileAndPath
Debug.Print “Saving “ & strFileAndPath
End IfLoad this attachment to the Attachments field of the target table.rstTargetAttachments.AddNew
rstTargetAttachments.Fields(“FileData”).LoadFromFile _
(strFileAndPath)
rstTargetAttachments.Update
Kill strFileAndPath
rstSourceAttachments.MoveNextPart II Writing VBA Code to Exchange Data between Office Components