S
Salad
I'm not getting a subroutine to return the correct counts based on using
the Restrict method. Is it because I am passing the wrong date format?
If I pass a comparison: Received >= Date1 And < Date2, I get all recs
greater/equal date1.
If I only want records for Date1, I get 0 records. Received = Date1
If I want all records >=1 date, I get correct count. Received >= Date1
Below I show the call to the subroutine and by routine. Any clue what I
am doing wrong? Thanks for any advice.
RestrictItems _
"00000000F01460E0716E454B8398DD735E95C4CA82800000", _
"2/24/2010", "2/25/2010"
Sub RestrictItems(strEntryID As String, _
strDate1 As String, strDate2 As String)
Dim olApp As Object
Dim olNS As Object
Dim olFolders As Object
Dim olItems As Object
Dim olMailItem As Object
Dim olRestrict As Object
Set olApp = GetObject(, "Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olFolders = _
olApp.GetNamespace("Mapi").GetFolderFromID(strEntryID)
Set olItems = olFolders.Items
'1. this line returns all items from both dates. Incorrect
Set olRestrict = olItems.Restrict("[CreationTime] >= """ _
& strDate1 & """ And [ReceivedTime] < """ & strDate2 & """")
'2. this line returns 0. Incorrect
Set olRestrict = olItems.Restrict("[CreationTime] = """ & _
strDate1 & """")
'3. this line returns all items from both dates. Correct
Set olRestrict = olItems.Restrict("[CreationTime] >= """ _
& strDate1 & """")
'used for all 3 options/comparisons
MsgBox "Count is " & olRestrict.Count
End Sub
the Restrict method. Is it because I am passing the wrong date format?
If I pass a comparison: Received >= Date1 And < Date2, I get all recs
greater/equal date1.
If I only want records for Date1, I get 0 records. Received = Date1
If I want all records >=1 date, I get correct count. Received >= Date1
Below I show the call to the subroutine and by routine. Any clue what I
am doing wrong? Thanks for any advice.
RestrictItems _
"00000000F01460E0716E454B8398DD735E95C4CA82800000", _
"2/24/2010", "2/25/2010"
Sub RestrictItems(strEntryID As String, _
strDate1 As String, strDate2 As String)
Dim olApp As Object
Dim olNS As Object
Dim olFolders As Object
Dim olItems As Object
Dim olMailItem As Object
Dim olRestrict As Object
Set olApp = GetObject(, "Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olFolders = _
olApp.GetNamespace("Mapi").GetFolderFromID(strEntryID)
Set olItems = olFolders.Items
'1. this line returns all items from both dates. Incorrect
Set olRestrict = olItems.Restrict("[CreationTime] >= """ _
& strDate1 & """ And [ReceivedTime] < """ & strDate2 & """")
'2. this line returns 0. Incorrect
Set olRestrict = olItems.Restrict("[CreationTime] = """ & _
strDate1 & """")
'3. this line returns all items from both dates. Correct
Set olRestrict = olItems.Restrict("[CreationTime] >= """ _
& strDate1 & """")
'used for all 3 options/comparisons
MsgBox "Count is " & olRestrict.Count
End Sub