Home > front end >  DASL filter using multiple conditions in VBA
DASL filter using multiple conditions in VBA

Time:06-03

I would like to use a DASL filter with multiple conditions in it. I sucessfully managed to do it with two conditions:

    filterstring = "@SQL=""urn:schemas:httpmail:fromname"" LIKE '%" & sender & "%'" & _
    " AND ""urn:schemas:httpmail:subject"" LIKE '%" & subject & "%'"

but somehow it doesn't work with three:

    filterstring = "@SQL=""urn:schemas:httpmail:subject"" LIKE '%" & subject & "%'" & _
    " AND ""urn:schemas:httpmail:datereceived"" LIKE '%" & received_date & "%'" & _
    " AND ""urn:schemas:httpmail:datereceived"" LIKE '%" & received_date_plus & "%'"

(The variables are previously defined.)

CodePudding user response:

The LIKE operator is used for string properties. You need to use < and > to compare date time values (and never use equality operators). Read more about that in the Filtering Items Using a Date-time Comparison article.

filterstring = "@SQL=""urn:schemas:httpmail:subject"" LIKE '%" & subject & "%'" & _
    " AND ""urn:schemas:httpmail:datereceived"" > '" & Format(received_date ,"General Date")& "' & _
    " AND ""urn:schemas:httpmail:datereceived"" < '" & Format(received_date_plus, "General Date")  & "'"

Pay attention to the fact that dates should be formatted like Outlook expects them. So, it makes sense to use the Format function available in VBA.

Also you may find the following articles helpful:

  • Related