OL98: Incorrect Count Property Using Recurring Appointments

ID: Q230115


The information in this article applies to:
  • Microsoft Outlook 98


SYMPTOMS

You use the Count property to determine the number of appointments in a collection, but the number returned is 2147843647.


CAUSE

You used the IncludeRecurrences method in the Outlook object model to retrieve recurring appointments. If any of the recurring appointments do not have a specific end date, they will recur indefinitely. Therefore, the collection of appointments is infinitely large. 2,147,843,647 is the largest number of items a collection can contain. If you then use the Restrict method to limit the number of appointments to those within a certain date range, the Count property is not updated to reflect the number of items in the smaller collection.


RESOLUTION

The collection actually contains the correct number of appointments. Therefore, if you are looping through all of the appointments, do not use the For I = 1 to Items.Count approach. Instead, use the For..Each construct to loop through the items.

The following Automation subroutine illustrates both the problem and the approach to correct the problem. Be sure to set a reference to the Microsoft Outlook 98 Object Model before running this code.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

Sub NumberOf1999Appts()
   
   Dim oOutApp As Outlook.Application
   Dim oNS As Outlook.NameSpace
   Dim CalFolder As Outlook.MAPIFolder
   Dim CalItems As Outlook.Items
   Dim ResItems As Outlook.Items
   Dim sFilter As String
   Dim iNumRestricted As Integer
   Dim itm As Object

   Set oOutApp = New Outlook.Application
   Set oNS = oOutApp.GetNamespace("MAPI")

   ' Use the default calendar folder
   Set CalFolder = oNS.GetDefaultFolder(olFolderCalendar)

   ' Get all of the appointments in the folder
   Set CalItems = CalFolder.Items

   ' Sort all of the appointments based on the start time
   CalItems.Sort "[Start]"

   ' Make sure to include all of the recurrences
   CalItems.IncludeRecurrences = True

   'create the Restrict filter to return all 1999 appointments
   sFilter = "[Start] >= '" & Format("1/1/1999 12:00am", _
      "ddddd h:nn AMPM") & "'" & " And [End] < '" & _
      Format("1/1/2000 12:00am", "ddddd h:nn AMPM") & "'"

   ' Apply the filter to the collection
   Set ResItems = CalItems.Restrict(sFilter)

   ' This will return 2147843647 if any recurring appointment does not have an end date
   MsgBox ResItems.Count

   iNumRestricted = 0

   'Loop through the items in the collection. This will not loop infinitely.
   For Each itm In ResItems
      iNumRestricted = iNumRestricted + 1
   Next

   ' Display the actual number of appointments in 1999.
   MsgBox iNumRestricted

   Set itm = Nothing
   Set ResItems = Nothing
   Set CalItems = Nothing
   Set CalFolder = Nothing
   Set oNS = Nothing
   Set oOutApp = Nothing

End Sub 


REFERENCES

For more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base:

Q180826 OL98: Resources for Custom Forms and Programming
Q182349 OL98: Questions About Custom Forms and Outlook Solutions

Additional query words: OutSol OutSol98 98

Keywords : kbdta
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.