Importing Outlook Emails

Derang

New member
Local time
Today, 13:31
Joined
Oct 9, 2009
Messages
3
Hi,

I'm using the below code to import the contents of an outlook folder into an access 97 database but need to also capture any attachments. I'm thinking along the lines of saving the attachments to disk and recording the file path as a hyperlink in a field within the recordset. Although i've no idea how to do this.

Could anyone show me how to do this?

Thanks in advance.


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 adoDbase As DAO.Database
Dim adoConn As DAO.Connection
Dim adoRS As DAO.Recordset
Dim intCounter As Integer

Set adoDbase = OpenDatabase _
("C:\Documents and Settings\901639\Desktop\Email test.mdb")
Set adoRS = adoDbase.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
adoRS.AddNew
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("Recd") = .ReceivedTime
adoRS("FromAddress") = .SenderEmailAddress
adoRS("FromType") = .SenderEmailType
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("Importance") = .Importance
adoRS.Update
End If

End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
MsgBox "Import Succesful"
End Sub
 

Users who are viewing this thread

Back
Top Bottom