Restrict method question on email. What am I doing wrong?

  • Thread starter Thread starter Salad
  • Start date Start date
Status
Not open for further replies.
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
 
You shoud always use a range for date/time properties.

Date = 2/24/2010

makes no sense even if you have a matching item with Date = "2/24/2010

00:00:000", firstly because there is always a roundoff error, and secondly

because I suspect that when you say

Date = 2/24/2010

you really mean

(Date >= "2/24/2010 00:00:000") And (Date < "2/25/2010 00:00:000")

Dmitry Streblechenko (MVP)

-

"Salad" <salad@oilandvinegar.com> wrote in message

news:5dmdnauvb-C_URvWnZ2dnUVZ_omdnZ2d@earthlink.com...
> 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
 
Dmitry Streblechenko wrote:


> You shoud always use a range for date/time properties.
> Date = 2/24/2010
> makes no sense even if you have a matching item with Date = "2/24/2010
> 00:00:000", firstly because there is always a roundoff error, and secondly
> because I suspect that when you say
> Date = 2/24/2010
> you really mean
> (Date >= "2/24/2010 00:00:000") And (Date < "2/25/2010 00:00:000")
>


Thanks. Got it working now.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Outlook Contact Item.Restrict where FullName is NULL Outlook VBA and Custom Forms 3
R How to restrict GWSMO sync to Outlook Send/Receive cycles Using Outlook 0
B oContacts.Items.Restrict Misses Some Contacts Outlook VBA and Custom Forms 3
K Disabling import/export button to restrict PST creation Using Outlook 3
A .restrict results changing after moving to Exchange online Outlook VBA and Custom Forms 0
L Restrict accepted appts to specific calendar Using Outlook 2
oliv- .RESTRICT returning birthdays regardless of the filtering date Outlook VBA and Custom Forms 8
M Using .Restrict with a UserProperty in an Exchange folder Outlook VBA and Custom Forms 4
JorgeDario restrict access to a certain folder with vba Outlook VBA and Custom Forms 3
JorgeDario How to restrict the creation of new folders? Outlook VBA and Custom Forms 2
C Outlook 2010, Need to restrict domain users from installing any sort of a addin in outlook Using Outlook 2
M Restrict throwing 'Condition is not valid' error Outlook VBA and Custom Forms 5
M Restrict Appointments by EntryID not working Outlook VBA and Custom Forms 1
M A plug in (or method) to keep email message formatting after it expires Using Outlook 1
E Complite error on SaveAsFile method Outlook VBA and Custom Forms 2
oliv- FASTEST METHOD TO ENUMERATE FOLDERS Outlook VBA and Custom Forms 3
Fozzie Bear Correct Method to set up Outlook.com accounts as Exchange Using Outlook.com accounts in Outlook 7
Diane Poremsky My Speedy CPAO Modification Method Using Outlook 0
N Get the seconds with userproperties.add method VBA Outlook Outlook VBA and Custom Forms 4
S Best method to use Outlook Standalone with iPhone Using Outlook 13
G run-time 438: object doesn't support this property or method Using Outlook 2
A Need method to rapidly correct telephone contact telephone number formatting Using Outlook 1
C MailItem Find method doesn't work Using Outlook 0
S Looking for client-side method (Outlook 2007/Exchange 2007) for users to delete Outlook VBA and Custom Forms 2
S MailItem Find Method question Outlook VBA and Custom Forms 6
A SmallScroll Method Outlook VBA and Custom Forms 1
D Call add-in method from macro? Outlook VBA and Custom Forms 1
P Question on getExchangeUser method in Outlook Add-in Outlook VBA and Custom Forms 3
P pasteface method crashing outlook Outlook VBA and Custom Forms 7
M Create email from Access on Outlook and make sure that email has beensent using WithEvents method Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Question about Outlook 2021 and Gmail Using Outlook 8
G Question marks in messages Using Outlook 2
e_a_g_l_e_p_i Question about calendar Using Outlook 5
e_a_g_l_e_p_i Question about installing my Gmail account on my iPhone but still getting messages downloaded to my desktop Outlook. Using Outlook 3
e_a_g_l_e_p_i Question about reinstalling Outlook 2021 Using Outlook 5
e_a_g_l_e_p_i question about 2-Step Verification with my gmail Using Outlook 0
D Question on removing an alias Using Outlook 1
O Newbie question: how to sync two Outlook -Exchange and IMAP- calendars? Using Outlook 4
D a general question re how backup programs handle pst files ... I have no problems, just curious Using Outlook 1
e_a_g_l_e_p_i A few question before I decide to switch to Pop from imap Using Outlook 9
D.Moore SendAndReceive question Outlook VBA and Custom Forms 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
N Question Using Outlook 8
D Shared Mailbox question Exchange Server Administration 1
CWM030 Another Quarantine question Exchange Server Administration 0
E Outlook 2010 Can somebody tell me , the question associated with OST format Using Outlook 1
CWM030 A quick question for Diane about Exchange Exchange Server Administration 2
CWM030 Email Catagorties question Using Outlook 1
MahdeeyaAbdulla Friend's outlook question Using Outlook 1
e_a_g_l_e_p_i Question about address book in Outlook 2010 Using Outlook 9

Similar threads

Back
Top