I've learned that EntryID will not stay constant in certain conditions. I've learned that PR_SEARCH_KEY may be a better property to rely on as a unique identifier but I can't figure out how to find an email using this property. Any ideas?
Code:
Public Sub search_test(key As String)
Dim olNS As NameSpace
Dim FolderInbox As MAPIFolder
Dim filtered_items As Items
Dim olMail As MailItem
Dim strFilter As String
Set olNS = GetNamespace("MAPI")
Set FolderInbox = olNS.GetDefaultFolder(olFolderInbox)
'strFilter = "@SQL= urn:schemas:httpmail:subject LIKE '%Notice Regarding%'"
'strFilter = "@SQL= urn:schemas:httpmail:textdescription LIKE '%<Email Body>%'"
strFilter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x300B0102"" = '" & key & "'"
Set filtered_items = FolderInbox.Items.Restrict(strFilter)
If filtered_items.Count = 0 Then
GoTo empty_objects
End If
For Each olMail In filtered_items
Debug.Print olMail.Subject
Debug.Print olMail.SenderEmailAddress
Next olMail
empty_objects:
Set FolderInbox = Nothing
Set olNS = Nothing
End Sub