Counting Appointments

B

baggers

Hi Guys
I'm trying to count the number of appointments in a calendar using the
restrict method.
If I add "items.IncludeRecurrences = True" then the numbers returned all
equal 2147483647.

Here is a code snippet:
dateFrom = Date.Today
dateTo = CDate("2014-01-01")
strFind = "[Start] >= " & DoubleQuote(Format(dateFrom, "dd MMM yyyy")) & "
AND [Start] < " & DoubleQuote(Format(dateTo, "dd MMM yyyy"))
items = mapi.GetFolderFromID(sID).Items
items.Sort("[Start]")
items.IncludeRecurrences = True
restrictedItems = items.Restrict(strFind)
itemCounter = itemCounter + restrictedItems.Count

can anyone see where the problem lies?

Thanks
 
S

Sue Mosher [MVP]

That's a known side effect of using IncludeRecurrences: Count isn't
meaningful. To get an accurate count, you can loop through the filtered
Items collection in a For Each ... Next loop and increment a counter
variable on each pass.
 
B

baggers

Sue
Thanks for that answer, it explains why I was getting strange numbers.

The method you suggest is terribly slow (we have multiple calendars in which
there are recurring appointments with no end date).
Do you know of a quicker way to get the number of appointments between two
specific dates?

Thanks
Simon.

Sue Mosher said:
That's a known side effect of using IncludeRecurrences: Count isn't
meaningful. To get an accurate count, you can loop through the filtered
Items collection in a For Each ... Next loop and increment a counter
variable on each pass.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


baggers said:
Hi Guys
I'm trying to count the number of appointments in a calendar using the
restrict method.
If I add "items.IncludeRecurrences = True" then the numbers returned all
equal 2147483647.

Here is a code snippet:
dateFrom = Date.Today
dateTo = CDate("2014-01-01")
strFind = "[Start] >= " & DoubleQuote(Format(dateFrom, "dd MMM yyyy")) & "
AND [Start] < " & DoubleQuote(Format(dateTo, "dd MMM yyyy"))
items = mapi.GetFolderFromID(sID).Items
items.Sort("[Start]")
items.IncludeRecurrences = True
restrictedItems = items.Restrict(strFind)
itemCounter = itemCounter + restrictedItems.Count

can anyone see where the problem lies?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top