Microsoft KB Archive/178509

= How To Write a VBScript CDO (1.x) MessageFilter in an ASP Page =

Article ID: 178509

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q178509



SUMMARY
You can use a message filter in an Active Server Page (ASP) utilizing Microsoft Visual Basic Script (VBScript) to filter your appointment calendar. This article contains sample code that demonstrates how to use VBScript for the message filter.

NOTE: This article contains a seemingly contradictory line of code.

In the example below, the variable "StartTime" is used to filter for meetings that start at or after a particular time. "EndTime" is used to filter for meetings that end before or at a particular time. The confusion arises from where these variables are used.

You pass "EndTime" with "CdoPR_START_DATE" and you pass "StartTime" with "CdoPR_END_DATE".

This is not a typographical error, the apparently contradictory code is correct.



MORE INFORMATION
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 Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sample Code
NOTE: This sample code assumes the target system has access to an installed and registed copy of CDO (1.2, 1.21).

Create a new ASP file and paste the following code into the ASP file: <%@ LANGUAGE="VBSCRIPT" %>

    Document Title   <%  Const strServer                 = "MyExchangeServer" Const strMailbox               = "MyMailbox" Const CdoDefaultFolderCalendar = 0 Const CdoPR_START_DATE         = &H600040 Const CdoPR_END_DATE           = &H610040 Dim objSession Dim objCalendarFolder Dim objAppointments Dim objAppointmentFilter Dim objOneAppointment Dim strProfileInfo Dim StartTime Dim EndTime Dim objAppointmentFilterField1 Dim objAppointmentFilterField2

strProfileInfo = strServer & vbLf & strMailbox Set objSession = Server.CreateObject("MAPI.Session") objSession.Logon, , False, False, 0, True, strProfileInfo

'Fill in a date/time using a 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 'all your appointments on January 1, 1998, you would use 'StartTime = #1/1/98# 'EndTime = #1/2/98# 'This combination filters 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 = #12/18/97 2:00:00 PM# EndTime = #12/19/97# Set objCalendarFolder = _ objSession.GetDefaultFolder(CdoDefaultFolderCalendar) Set objAppointments = objCalendarFolder.Messages Set objAppointmentFilter = objAppointments.Filter

'NOTE: Use the EndTime in the Start_Date field and the 'StartTime in the End_Date field. Set objAppointmentFilterField1 = _ objAppointmentFilter.Fields.Add(CdoPR_START_DATE, EndTime) Set objAppointmentFilterField2 = _ objAppointmentFilter.Fields.Add(CdoPR_END_DATE, StartTime)

For Each objOneAppointment In objAppointments Response.Write("objOneAppointment.Subject = " & _            objOneAppointment.Subject & " ") Response.Write("objOneAppointment.StartTime = " & _            objOneAppointment.StartTime & " ") Response.Write("objOneAppointment.EndTime = " & _            objOneAppointment.EndTime & " ") Response.Write("objOneAppointment.Duration = " & _            objOneAppointment.Duration & "  ") Next Response.Write("Done ") objSession.Logoff Set objOneAppointment = Nothing Set objAppointments = Nothing Set objCalendarFolder = Nothing Set objSession = Nothing %>

 

Keywords: kbcode kbhowto kbinetdev kbmsg KB178509

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.