A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old February 25th 10, 07:14 PM posted to microsoft.public.outlook.program_vba
Salad
external usenet poster
 
Posts: 24
Default Restrict method question on email. What am I doing wrong?

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(strEntr yID)
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
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Restrict() method and Null values Craig Buchanan[_2_] Add-ins for Outlook 3 December 16th 08 04:04 PM
Restrict Method - Find only blank fields - VBA Irene Outlook and VBA 1 June 5th 07 04:25 PM
Using Restrict method to select emails Jerry West Outlook and VBA 16 April 26th 07 05:48 PM
Restrict method problem Mike Epp Outlook and VBA 2 April 7th 06 07:03 PM
Restrict Method DNW emanson Outlook and VBA 14 March 28th 06 05:47 AM


All times are GMT +1. The time now is 07:55 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.