HOWTO: Write a VBScript MessageFilter in an ASP Page

ID: Q178509

The information in this article applies to:

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

Sample Code

Create a new ASP file and paste the following code into the ASP file:

   <%@ LANGUAGE="VBSCRIPT" %>

   <HTML>
   <HEAD>
   <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
   <META HTTP-EQUIV="Content-Type" content="text/html;charset=iso-8859-1">
   <TITLE>Document Title</TITLE>
   </HEAD>
   <BODY>
   <%
   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 & "<br>")
     Response.Write("objOneAppointment.StartTime = " & _
             objOneAppointment.StartTime & "<br>")
     Response.Write("objOneAppointment.EndTime = " & _
             objOneAppointment.EndTime & " <br>")
     Response.Write("objOneAppointment.Duration = " & _
             objOneAppointment.Duration & "<br> <br>")
   Next
   Response.Write("Done <br>")
   objSession.Logoff
   Set objOneAppointment = Nothing
   Set objAppointments = Nothing
   Set objCalendarFolder = Nothing
   Set objSession = Nothing
   %>

   </BODY>
   </HTML>

Keywords          : kbcode kbASP100 kbCDO120 kbMsg kbVBScript kbGrpMsg kbInetDev 
Version           : WINDOWS:1.2; WINNT:1.0,1.0b
Platform          : WINDOWS winnt
Issue type        : kbhowto

Last Reviewed: May 19, 1999