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.