'Search string syntax for Restrict method
I'm trying to pull a set of five emails from a specified Outlook folder based on two conditions - the (partial) subject line, and received between two specified dates. I've used the Items.Restrict
method in the past for a similar task, filtering only on the partial subject line, but I'm struggling with including the dates as well.
My template, the line that works correctly, looks thus:
strFilter = "@SQL=""urn:schemas:httpmail:subject"" like '%" & strSubject & "%'"
Set itmFiltered = fld.Items.Restrict(strFilter)
I've tried including the dates in various ways. Based on the help file, I thought something like this would work:
strFilter = "@SQL=""urn:schemas:httpmail:subject"" like '%" & strSubject & "%'"
If Len(strStart) <> 0 then
strfilter = strfilter & " AND ""urn:schemas:httpmail:Received:"" >='" & strStart & "'"
End If
set itmFiltered = fld.Items.Restrict(strfilter)
Error, every time.
I also tried setting it to just filter by the date, without including the subject line, like this:
strFilter = "@SQL=""urn:schemas:httpmail:Received: >=""'" & strStart & "'"
Again, no luck.
So, my questions:
What syntax do I need to use the Items.Restrict method to filter by date?
And what syntax do I need to use the Items.Restrict method to filter by multiple fields?
Solution 1:[1]
Firstly, you have an ":"
at the end of""urn:schemas:httpmail:Received:""
. Secondly, there is no such DASL name. Did you mean "datereceived"
?
You need to use "urn:schemas:httpmail:datereceived"
or "http://schemas.microsoft.com/mapi/proptag/0x0E060040"
. Use OutlookSpy (I am its author) to look up a DASL property name - click IMessage button, select the property, look at the DASL edit box.
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 | Dmitry Streblechenko |