Handling outlook attachments

By derang ·

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?


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("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


End If
End With

Set RS = Nothing
Set Conn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Hardware Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums