Load specific email items to Access Table

RLN88360

New member
Local time
Today, 08:18
Joined
Sep 23, 2011
Messages
2
RE: Win7Pro / Access 2010 / Outlook 2010

In my Access app, I need to be able to retrieve a specific email by date/time, then take the Subject, the Date received and body of that email and save it to a column in a table.

Does anyone know how to do this in Access VBA?

Thanks.
 
Here is a code snip I have. I never had a chance to test this, but it should get you started down the right road:

Code:
Public Sub ReadInbox()
Dim TempRst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object

PauseWorkspace
    DoCmd.RunSQL DELETE  FROM tbl_outlooktemp
ResetWorkspace

Set OlApp = CreateObject(Outlook.Application)
Set Inbox = OlApp.GetNamespace(Mapi).GetDefaultFolder(olFolderInbox)
Set InboxItems = Inbox.Items
Set TempRst = CurrentDb.OpenRecordset(tbl_OutlookTemp)

For Each Mailobject In InboxItems
    If Mailobject.UnRead Then
        With TempRst
            .AddNew
            !Subject = Mailobject.Subject
            !from = Mailobject.SenderEmailAddress
            !To = Mailobject.To
            !body = Mailobject.body
            !DateSent = Mailobject.SentOn
            .Update
        End With
        Mailobject.UnRead = False
'        Mailobject.Delete
    End If
Next

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

Users who are viewing this thread

Back
Top Bottom