With help from another expert yesterday I have got the code below to do the following
- From Access
- Look at the sent items in the Outlook Sent Items Folder
- Find an e-mail with a certain phrase in the subject line
- forward that e-mail to a new recipient
If possible - I would like to now restrict the items I iterate through in the Sent Items Folder to just the ones containing my phrase (Too many items to go through them all)
I dont know how to change it to only look at just the e-mails with the subject line I have declared in the variable ~ strFilter.
Do you know if this is possible and if so how would I do this? Thanks
Code I have so far is....
Dim mOutLookApp As Outlook.Application
Dim mNameSpace As Outlook.NameSpace
Dim sentBox As Outlook.MAPIFolder
'Dim mitem As Outlook.MailItem
Dim mItem As Object
Dim strFilter As String
Dim strExistingSubject As String
Set mOutLookApp = New Outlook.Application
Set mNameSpace = mOutLookApp.GetNamespace("MAPI")
mNameSpace.Logon , , False, True
strFilter = "Set up Request: 2010082013311101"
'ideally here I would just like to look at the e-mails with the above string in the subject line...
'i tried to use "Restrict" but I think I do not have the correct syntax
Set sentBox = mOutLookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
sHTMLBody = ""
For i = 1 To sentBox.Items.Count
Set mItem = sentBox.Items(i)
'then you can process each item
'forward the message
strExistingSubject = mItem.Subject
If strFilter = strExistingSubject Then
'show for testing only
'add in recipients...do other stuff
mItem.To = "M@abc.xy"
mItem.Body = "Hello" & vbCrLf & mItem.Body