OUTLOOK vba filter with like statement

Viewed 1242

I want to put a like statement as I want to filter email that starts with tmeadmin@

This code breaks on the line with the like statement. How do I fix it?

 Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim InboxMsg As Object
    Dim Inbox As Outlook.Folder
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set Inbox = objNamespace.GetDefaultFolder(olFolderInbox)
    Dim myRestrictItems As Outlook.Items
     Dim filter As String
     filter = "urn:schemas:httpmail:fromemail LIKE 'tmeadmin@%'"

      MsgBox (filter)
 Set myRestrictItems = Inbox.Items.Restrict(filter)
1 Answers

To use the LIKE operator, you need to use the @SQL syntax:

filter = "@SQL=urn:schemas:httpmail:fromemail LIKE 'tmeadmin@%'"
Related