R
Robert Davidson
When I use an AdvancedSearch with a received date criteria, the criteria is
not precise. It appears to subtract a couple hours.
When I enter it by hand in Customize View > Advanced, it works as expected.
If you run the below code in a folder where you keep messages that are close
in time, it should tell you that there are more message than exist that
arrived after the message you have selected.
While it should not make a difference, the folders I am searching
with have more than 2000 messages and less then 10,000. The folder is sorted
by received descending and I am reproducing by selecting one of the top 10
messages. I have tested against a PST store and an Exchange default folder
store.
Outlook 2002 (10.4219.4219) SP-2
Does anyone have any ideas on how to fix this - other than doing a for each
through the results and comparing the criteria date against the received
date again?
Best Regards,
Robert Davidson
Sub TestDateCriteria()
Dim SearchDate As Date
Dim sScope As String
Dim sFilter As String
Dim oSearch As Search
With Application.ActiveExplorer
sScope = "SCOPE ('shallow traversal of """ & .CurrentFolder.FolderPath &
"""')"
With .Selection.Item(1)
SearchDate = .ReceivedTime
End With
sFilter = "(""DAV:isfolder"" = false AND ""DAV:ishidden"" = false) AND "
sFilter = sFilter & "(""urn:schemas:httpmail:datereceived"" >= '" &
SearchDate & "')"
Debug.Print sFilter
Set oSearch = Application.AdvancedSearch(sScope, sFilter, False)
End With
Do Until oSearch.Results.Count > 0
DoEvents
DoEvents
Loop
MsgBox oSearch.Results.Count
End Sub
not precise. It appears to subtract a couple hours.
When I enter it by hand in Customize View > Advanced, it works as expected.
If you run the below code in a folder where you keep messages that are close
in time, it should tell you that there are more message than exist that
arrived after the message you have selected.
While it should not make a difference, the folders I am searching
with have more than 2000 messages and less then 10,000. The folder is sorted
by received descending and I am reproducing by selecting one of the top 10
messages. I have tested against a PST store and an Exchange default folder
store.
Outlook 2002 (10.4219.4219) SP-2
Does anyone have any ideas on how to fix this - other than doing a for each
through the results and comparing the criteria date against the received
date again?
Best Regards,
Robert Davidson
Sub TestDateCriteria()
Dim SearchDate As Date
Dim sScope As String
Dim sFilter As String
Dim oSearch As Search
With Application.ActiveExplorer
sScope = "SCOPE ('shallow traversal of """ & .CurrentFolder.FolderPath &
"""')"
With .Selection.Item(1)
SearchDate = .ReceivedTime
End With
sFilter = "(""DAV:isfolder"" = false AND ""DAV:ishidden"" = false) AND "
sFilter = sFilter & "(""urn:schemas:httpmail:datereceived"" >= '" &
SearchDate & "')"
Debug.Print sFilter
Set oSearch = Application.AdvancedSearch(sScope, sFilter, False)
End With
Do Until oSearch.Results.Count > 0
DoEvents
DoEvents
Loop
MsgBox oSearch.Results.Count
End Sub