Discussion:
Outlook Restrict on SentOn (using Between)
(too old to reply)
McKilty
2009-09-28 14:57:58 UTC
Permalink
Hello all,

I am trying to figure to the proper syntax for using Restrict on the
SentOn field. I need to restrict between two dates, but so far
nothing is filtering to the exact date range I'm looking for. I have
tried:

Set mItemCollection = mItemCollection.Restrict("[SentOn] > '" &
dteStart & "' AND [SentOn] < '" & dteEnd & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] = '" &
dteStart & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] Between '" &
dteStart & "' AND '" & dteEnd & "'")

Thanks for the help.
Sue Mosher [MVP]
2009-09-28 15:22:20 UTC
Permalink
Only your first statement is workable. Between is not an available operator,
and SentOn includes the time element, not just a date, so you're unlikely to
find an exact match. See http://www.outlookcode.com/article.aspx?id=30. I
recommend that you use a separate statement to build the query string so you
can examine it and, if you continue to have issues with this, post a
specific example in this thread so we can see how you're formatting the
dteStart and dteEnd values.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by McKilty
Hello all,
I am trying to figure to the proper syntax for using Restrict on the
SentOn field. I need to restrict between two dates, but so far
nothing is filtering to the exact date range I'm looking for. I have
Set mItemCollection = mItemCollection.Restrict("[SentOn] > '" &
dteStart & "' AND [SentOn] < '" & dteEnd & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] = '" &
dteStart & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] Between '" &
dteStart & "' AND '" & dteEnd & "'")
Thanks for the help.
McKilty
2009-09-28 15:47:46 UTC
Permalink
Post by Sue Mosher [MVP]
Only your first statement is workable. Between is not an available operator,
and SentOn includes the time element, not just a date, so you're unlikely to
find an exact match. Seehttp://www.outlookcode.com/article.aspx?id=30.  I
recommend that you use a separate statement to build the query string so you
can examine it and, if you continue to have issues with this, post a
specific example in this thread so we can see how you're formatting the
dteStart and dteEnd values.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by McKilty
Hello all,
I am trying to figure to the proper syntax for using Restrict on the
SentOn field.  I need to restrict between two dates, but so far
nothing is filtering to the exact date range I'm looking for.  I have
Set mItemCollection = mItemCollection.Restrict("[SentOn] > '" &
dteStart & "' AND [SentOn] < '" & dteEnd & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] = '" &
dteStart & "'")
Set mItemCollection = mItemCollection.Restrict("[SentOn] Between '" &
dteStart & "' AND '" & dteEnd & "'")
Thanks for the help.
Thanks Sue. Your link was very helpful.

Switching to a string rather than a date made it work.

Loading...