Microsoft KB Archive/254714

From BetaArchive Wiki

Article ID: 254714

Article Last Modified on 3/4/2004


  • Microsoft Outlook 2000 Standard Edition

This article was previously published under Q254714


The Sort method may sort a filtered appointments collection incorrectly when the first occurrence of a recurring AppointmentItem is also an Exception.


To resolve this problem, obtain the latest service pack for Microsoft Office 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

276367 OFF2000: How to Obtain the Latest Office 2000 Service Pack


Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This problem was first corrected in Microsoft Office 2000 Service Pack 3.


Steps to Reproduce Behavior

  1. Begin with a clean calendar.
  2. On today's date, create four appointments: "Test1", "Test2", "Test3", and "Test4".
  3. On yesterday's date, create two daily recurring appointments: "TestR1" and "TestR2".
  4. Right-click the first occurrence of "TestR1", click Delete, click Delete this one, and then click OK.
  5. In Microsoft Visual Basic 6.0, create a new standard EXE project, remove Form1, and then add a standard Module.
  6. Set a reference to "Microsoft Outlook Object Library."
  7. Paste the following code in the module code window and then execute it:
Sub Main()
  Dim oNS As NameSpace
  Dim myOLApp As Outlook.Application
  Dim myItems As Outlook.Items
  Dim oFolder As Outlook.MAPIFolder
  Dim oAppt As Outlook.AppointmentItem

  Dim sStartDate As String
  Dim sEndDate As String
  Dim sRestrict As String
  Dim sCurrentApptInfo As String

   Set myOLApp = CreateObject("Outlook.Application")
   Set oNS = myOLApp.GetNamespace("MAPI")
   sStartDate = "#" & Format(Date, "mm/dd/yyyy") & " 12:00 AM#"
   sEndDate = "#" & Format(DateAdd("d", 1, Date), "mm/dd/yyyy") & " 12:00 AM#"
  'Today's appointments.
   sRestrict = "(([start]>='" & sStartDate & "')and ([start]<'" & sEndDate & "'))"
   '''' Put this condition if you need Spanning Appointments.
   sRestrict = sRestrict & " or (([start]<='" & sStartDate & "') and ([end]>='" & sStartDate & "'))"
   Set oFolder = oNS.GetDefaultFolder(olFolderCalendar)
   Set myItems = oFolder.Items
   myItems.Sort "[Start]", False
   myItems.IncludeRecurrences = True
   Set myItems = myItems.Restrict(sRestrict)
   myItems.Sort "[Start]", False
   'Print the Appointment info.
   For Each oAppt In myItems
      sCurrentApptInfo = "Start: " & oAppt.Start & vbCrLf & _
                        "End: " & oAppt.End & vbCrLf & _
                        "All Day Event: " & oAppt.AllDayEvent & vbCrLf & _
                        "Is Recurring: " & oAppt.IsRecurring & vbCrLf & _
                        " - " & oAppt.Subject & " (" & oAppt.Location & ")"
     Debug.Print sCurrentApptInfo
    Set oAppt = Nothing
    Set myItems = Nothing
    Set oFolder = Nothing
    Set oNS = Nothing
    Set myOLApp = Nothing
End Sub


The results are as follows:

  • The "TestR1" recurring appointment sorts incorrectly.
  • The "TestR2" recurring appointment sorts correctly.

Keywords: kbbug kbfix kboutlookobj kbmsg kboffice2000sp3fix kbautomation kbofficexpsp1fix KB254714