PRB: CDO Filter on AppoinmentItems has Unexpected Behavior (192404)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.2
  • Collaboration Data Objects (CDO) 1.21

This article was previously published under Q192404

SYMPTOMS

When filtering on a collection of Collaboration Data Objects (CDO) AppoinmentItems, the Start and End dates must be reversed to make the filter work as expected.

Setting the CdoPR_START_DATE in a MessageFilter on AppointmentItems returns items that start on or before the specified date. Setting the CdoPR_END_DATE returns items that end on or after that date. Attempting to specify other properties to filter on or trying to set one of these properties but not the other results in an error of CDO_E_TOO_COMPLEX.

CAUSE

This is caused by the manner in which the CDO Filter handles the Start and End dates.

RESOLUTION

The solution is to reverse the Start and End dates as shown below:
   'You must add a Reference to Microsoft CDO version 1.21.
    Set objSession = CreateObject("MAPI.Session")

    objSession.Logon
    Set objCalendar = _
        objSession.GetDefaultFolder(MAPI.CdoDefaultFolderCalendar)
    Set oMsgColl = objCalendar.Messages

    Set oMsgFilter = oMsgColl.Filter
    oMsgFilter.Fields.Add CdoPR_START_DATE, "10/1/98"
    oMsgFilter.Fields.Add CdoPR_END_DATE, "9/1/98"

    Set oAppt = oMsgColl.GetFirst
    MsgBox oAppt.Subject

    Do While (Not oAppt Is Nothing)
       MsgBox oAppt.Subject
       Set oAppt = oMsgColl.GetNext
    Loop
    objSession.Logoff
				

STATUS

This behavior is by design.

REFERENCES

For additional information on creating filters for appointments, please see the following article in the Microsoft Knowledge Base:

178508 HOWTO: Write a VB MessageFilter for Your Appointment Collection


Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbcode kbMsg kbprb KB192404