strFile = _
SplitFileName(rstSourceAttachments.Fields(“FileName”))
Debug.Print “File name: “ & strFile
strFileAndPath = strDocsPath & strFile
Debug.Print “File and path: “ & strFileAndPath
On Error Resume Next
Check 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 Then
Save this attachment to a file in the Output Docs folder.
.Fields(“FileData”).SaveToFile strFileAndPath
Debug.Print “Saving “ & strFileAndPath _
& “ to “ & strDocsPath & “ folder”
End If
Add this attachment to the Attachments collection of the Outlook contact item.
Debug.Print “Adding attachment “ & strFileAndPath _
& “ to “ & con.FullName & “ contact”
con.Save
con.Attachments.Add Source:=strFileAndPath, _
Type:=olByValue
con.Close (olSave)
Kill strFileAndPath
.MoveNext
Loop
rstSourceAttachments.Close
End With
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End Sub
Public Sub CopyOutlookAttsToAccess(con _
As Outlook.ContactItem, rstTargetAttachments As _
DAO.Recordset2)
Part II Writing VBA Code to Exchange Data between Office Components