Hi team,
I am using the below given code to download mails into my db it works fine. However when downloading data from .to field I have a trouble sometimes emails are addressed to multiple recipients the current code only downloads data of one email address I wanted to download all the recipient details in different fields say to1 , to2 etc. is it possible could you assist me?
I am using the below given code to download mails into my db it works fine. However when downloading data from .to field I have a trouble sometimes emails are addressed to multiple recipients the current code only downloads data of one email address I wanted to download all the recipient details in different fields say to1 , to2 etc. is it possible could you assist me?
Code:
Private Sub sntml()
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim stfldr As Outlook.MAPIFolder
Dim stfldrItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
Dim emailCount as integer
Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set stfldr = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderSentMail)
Set rst= CurrentDb.OpenRecordset("ogmls")
Set stfldrItems = stfldr.Items
stfldrItems.Sort "[ReceivedTime]"
emailCount=1
For Each Mailobject In stfldrItems
With rst
.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
End With
emailCount = emailCount+1
if emailCount > 10 then
Exit For
end if
Next
Set OlApp = Nothing
Set stfldr = Nothing
Set stfldrItems = Nothing
Set Mailobject = Nothing
Set rst = Nothing
End Sub