Search code examples
excelvbaoutlookoutlook-filter

Excel VBA @SQL String filter


I have been struggling on making this statement a NOT statement:

strfilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%undeliverable%'"

this strfilter is being used in a items.restrict(strfilter), so obviously it's checking for all emails that contains the word undeliverable.

What I need to do is convert this statement so that it will EXCLUDE all emails with the subject containing the Words "undeliverable".

I've tried this but it returned a parse error:

"strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " NOT '%undeliverable%'"

thanks in advance.


Solution

  • The Correct syntax is

    Filter = "@SQL=" & " Not " & _
             "urn:schemas:httpmail:subject" & "" & _
             " Like '%undeliverable%'"
    

    Or I prefer this then Like

    strFilter = "@SQL=" & " Not " & _
                "urn:schemas:httpmail:subject" & "" & _
                " ci_phrasematch 'undeliverable'"