PDA

View Full Version : Import body of outlook messages into Microsoft Access



marlind
06-08-2009, 12:21 PM
Is there a way to import the text in a Microsoft Outlook 2003 message into a Microsoft Access 2003 database? I want to use data from a text message and automate populating a log I want to create. Thanks for any help.

arangogs
06-09-2009, 04:25 AM
Hi Marland,

this code will hopefully point you in the right direction and give you a start. It is taken from blueclaw-db.com I would post the link but it was not allowed


Private Sub ReadInbox
Dim TempRst As DAO.Recordset
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
DoCmd.RunSQL "Delete * from tbl_outlooktemp"
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
'
Set InboxItems = Inbox.Items
'
For Each Mailobject In InboxItems
If Mailobject.UnRead Then
With TempRst

.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
End With
End If
Next

Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
End Sub