Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Using VBA in Access - Find Sent Items on OUtlook iwht matching criteria in the Subject Line

Avatar of Access_MS
Access_MS asked on
Microsoft AccessOutlook
6 Comments1 Solution755 ViewsLast Modified:
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
            End If
    Next i
End Sub
Avatar of Chris Bottomley
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers