View Single Post
 
Old 10-17-2014, 05:02 AM
megatronixs megatronixs is offline Windows 7 32bit Office 2003
Advanced Beginner
 
Join Date: Aug 2012
Posts: 42
megatronixs is on a distinguished road
Default take emails from outlook mailbox and folders to Access

Hi all,

I have some code to take the emails form outlook to access database.
I was wondering how I could change the folder and subfolder where the emails should come from. Now it will take only the unread emails from the personal inbox. how can I change it to "Backup" folder that is from the: - New Line Products.

I'm also trying to show if an email has attachments or not.
Any help would be really great.

Code:
Option Compare Database
Private Sub Command14_Click()
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
        !SenderName = Mailobject.SenderName
        !To = Mailobject.To
        !Body = Mailobject.Body
        !ReceivedOn = Mailobject.ReceivedOn
        !SentOn = Mailobject.SentOn
        '!Attachments = Mailobject.Attachments 'the part that does not work
        !SenderEmailAddress = Mailobject.SenderEmailAddress 
        .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
Greetings.
Reply With Quote