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 Dbase As DAO.Database
Dim Conn As DAO.Connection
Dim RS As DAO.Recordset
Dim intCounter As Integer
Set Dbase = OpenDatabase _
("C:\Documents and Settings\901639\Desktop\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
RS.Update
End If
End With
Next
RS.Close
Set RS = Nothing
Set Conn = Nothing
Set ns = Nothing
Set objFolder = Nothing
MsgBox "Import Succesful"
End Sub
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 Dbase As DAO.Database
Dim Conn As DAO.Connection
Dim RS As DAO.Recordset
Dim intCounter As Integer
Set Dbase = OpenDatabase _
("C:\Documents and Settings\901639\Desktop\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
RS.Update
End If
End With
Next
RS.Close
Set RS = Nothing
Set Conn = Nothing
Set ns = Nothing
Set objFolder = Nothing
MsgBox "Import Succesful"
End Sub