AppointmentItem.Start appears to have different dates in it at different times RRS feed

  • Question

  • In writing a program that dumps requested day's appointments from Outlook calendars, I am confused at the content of AppointmentItem.Start.  My program uses this equation to select the appropriate day(s) records:

    strFind = "[Start] <= " & Quote(Format(dteEnd, "ddddd") & " 11:59 PM") & " AND [End] > " & Quote(Format(dteStart, "ddddd") & " 12:00 AM")

    Note:  "Quote" in the above is a string constant that has been set.

    This selection often contains instances of recurring records that "started" on an earlier date then I am searching for.  This suggests that AppointmentItem.Start contains the calendar date for this record.  However, when I debug.print the value appointmentitem.start to the immediate window the in the same program from this selection , the Start field yields the start date of the first instance of the recurring appointment.   Here is my entire code:

    Sub X()

    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim colCal As Outlook.Items
    Dim objAppt As Outlook.AppointmentItem

    Dim myRecipient As Outlook.Recipient

    On Error Resume Next

    Set objOL = CreateObject("outlook.application")
    Set objNS = objOL.GetNamespace("MAPI")

    Set myRecipient = objNS.CreateRecipient("DPK Conf RM SDPC 6130 SDPR-RESV")

    Set colCal = objNS.GetSharedDefaultFolder(myRecipient, olFolderCalendar).Items

    Set colSpanItems = DateSpan(colCal, #5/21/2012#, #5/25/2012#)

    For Each objAppt In colSpanItems
        If Left(objAppt.Organizer, 3) <> "DPK" Then
            Debug.Print objAppt.Start & ", " & objAppt.Duration & ", "; objAppt.End & ", " & objAppt.Organizer & _
            ", " & objAppt.Subject
            'Debug.Print objAppt.RecurrenceState
        End If

    Set objAppt = Nothing
    Set colSpanItems = Nothing
    Set colCal = Nothing

    End Sub

    Here is the code for the Function DateSpan() that appears in the above:

    Function DateSpan(colItems As Outlook.Items, dteStart As Date, dteEnd As Date) As Outlook.Items
    Dim colSpanItems As Outlook.Items
    On Error Resume Next
    colItems.Sort "[Start]"
    colItems.IncludeRecurrences = True
    strFind = "[Start] <= " & Quote(Format(dteEnd, "ddddd") & " 11:59 PM") & " AND [End] > " & _
              Quote(Format(dteStart, "ddddd") & " 12:00 AM")
    Set colSpanItems = colItems.Restrict(strFind)

    If Err = 0 Then
       Set DateSpan = colSpanItems
    End If

    Set colSpanItems = Nothing

    End Function

    Here is the code for the Function Quote that appears in the above:

    Function Quote(MyText)
        Quote = Chr(34) & MyText & Chr(34)
    End Function

    Any ideas or thoughts would be very welcome; I am really stumped by this.


    Tuesday, May 29, 2012 6:28 PM

All replies

  • could you explain again what seems to be the problem and write down simplest steps to reproduce it? (like create recurring appointment that starts on ... and has 3 occrances, do this and that...)

    Wednesday, May 30, 2012 7:24 AM