Hi,
I’m using the below code to import the contents of an outlook folder into an access 97 database, but also need to capture any attachments. I’d like to save the attachments to a folder on our network drive but record the saved filepath in the database as a hyperlink.
Any ideas how I can alter the code to achieve this?
Thanks.
Sub ExportMailByFolder()
‘Export specified fields from each mail
‘item in selected folder.
Dim ns As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Set ns = GetNamespace(“MAPI”)
Set objFolder = ns.PickFolder
Dim Dbase As DAO.Database
Dim Conn As DAO.Connection
Dim RS As DAO.Recordset
Dim intCounter As Integer
Dim strFolder As String
Dim myAttachment As Outlook.Attachment
strFolder = “C:\Documents and Settings\901639\Desktop\TEST\Attachments\”
Set Dbase = OpenDatabase _
(“C:\Documents and Settings\901639\Desktop\TEST\Email test.mdb”)
Set RS = Dbase.OpenRecordset(“Email”)
‘Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
‘Copy property value to corresponding fields
‘in target file.
If .Class = olMail Then
RS.AddNew
RS(“Subject”) = .Subject
RS(“Body”) = .Body
RS(“FromName”) = .SenderName
RS(“ToName”) = .To
RS(“Recd”) = .ReceivedTime
RS(“FromAddress”) = .SenderEmailAddress
RS(“FromType”) = .SenderEmailType
RS(“CCName”) = .CC
RS(“BCCName”) = .BCC
RS(“Importance”) = .Importance
‘ myAttachment.SaveAsFile strFolder & myAttachment.DisplayName
‘ RS(“Attachment”) = myAttachment
RS.Update
End If
End With
Next
RS.Close
Set RS = Nothing
Set Conn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub