ID: Q178508
The information in this article applies to:
You can use a Collaboration Data Objects (CDO) message filter in Microsoft Visual Basic to filter your appointment calendar. This article contains sample code that demonstrates how to use Visual Basic as a filter.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
1. Open a new Visual Basic standard executable project.
2. Create a reference to the Microsoft Collaboration Data Objects (CDO) 1.2
library (Cdo.dll).
3. Create a command button named "Command1" on the form.
4. Copy and paste the following code into the form:
Option Explicit
Const strServer As String = "MyExchangeServer"
Const strMailbox As String = "MyMailbox"
Private Sub Command1_Click()
Dim objSession As MAPI.Session
Dim objCalendarFolder As Folder
Dim objAppointments As Messages
Dim objAppointmentFilter As MessageFilter
Dim objOneAppointment As AppointmentItem
Dim strProfileInfo As String
Dim StartTime As Date
Dim EndTime As Date
Dim objAppointmentFilterField1 As Field
Dim objAppointmentFilterField2 As Field
Screen.MousePointer = vbHourglass
StrProfileInfo = strServer & vbLf & strMailbox
Set objSession = New MAPI.Session
objSession.Logon , , False, False, 0, True, strProfileInfo
'Fill in a date/time using the vbDate format.
'For example StartTime = #1/1/98 9:30 AM#. This vbDate
'filters appointments that started AFTER 9:30 AM on
'January 1, 1998. Use StartTime and EndTime in combination
'to filter a specific date. For example, if you wanted to filter
'for all your appointments on January 1, 1998, use
'StartTime = #1/1/98#
'EndTime = #1/2/98#
'This combination filters for all appointments starting
'AFTER Janury 1, 1998 at midnight, and all appointments ending
'BEFORE January 2, 1998 at midnight.
'You can further refine your filter by adding times to the
'StartTime and EndTime.
StartTime = #m/d/yy hh:mm XX#
EndTime = #m/d/yy hh:mm XX#
Set objCalendarFolder = _
objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
Set objAppointments = objCalendarFolder.Messages
Set objAppointmentFilter = objAppointments.Filter
'NOTE: Pass the EndTime parameter to the START_DATE field and the
' StartTime parameter to the END_DATE field.
Set objAppointmentFilterField1 = _
objAppointmentFilter.Fields.Add(ActMsgPR_START_DATE, EndTime)
Set objAppointmentFilterField2 = _
objAppointmentFilter.Fields.Add(ActMsgPR_END_DATE, StartTime)
For Each objOneAppointment In objAppointments
Debug.Print "objOneAppointment.Subject = " & _
objOneAppointment.Subject
Debug.Print "objOneAppointment.StartTime = " & _
objOneAppointment.StartTime
Debug.Print "objOneAppointment.EndTime = " & _
objOneAppointment.EndTime
Debug.Print
Next
objSession.Logoff
Set objOneAppointment = Nothing
Set objAppointments = Nothing
Set objCalendarFolder = Nothing
Set objSession = Nothing
Screen.MousePointer = vbNormal
End Sub
5. Run the project and click Command1. Your immediate window displays all
appointments for the selected date.
See the "MessageFilter Object" and "AddressEntryFilter Object" topics in the Microsoft Developer Network Library.
Keywords : kbcode kbCDO120 kbMsg kbVBp kbGrpMsg
Version : WINDOWS:1.2
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 8, 1999