'Filter sent items based on the recipients email address in Outlook

I am working on an activity facility which stores incoming and outgoing emails in the database for different contacts. I do this by looping through each folder in my namespace and restricting emails based on the sender email address.

I have managed to store incoming emails so far, but outgoing emails are completely ignored for some reason. I am assuming I am doing the "Mailtiems.Restrict" incorrectly, however I could not figure out what it may be. Please see the code below:

If folder.Name = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Name Then
    outlookItems = folder.Items
    outlookItems = outlookItems.Restrict("[SenderEmailAddress] = " & Quote(txtContactPersonalEmailAddress.Text) & " AND [MessageClass] = 'IPM.Note'")
    ' Count total folder items for progress bar
    iOutlookFolderTotalMailItems = outlookItems.Count

The count always returns 0 even though I have sent an email to this contact and it appears in my "Sent Items" folder. I wonder if there is a different property I will need to use for "Sent Items" other than "SenderEmailAddress".



Solution 1:[1]

If you are searching for the recipients rather than the sender, you should not be specifying SenderEmailAddress - the sender will always be you.

See Filter sent items outlook by address in Excel VBA

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1