Keep up-to-date on Microsoft's new .NET initiative, which includes VB7, VS7, ASP+, Web services, the new C# language, the Microsoft .NET framework including ADO+, and much more. Just click the link for a free subscription.
http://www.codeoftheweek.com/pinnacle
If you have any tips to contribute, email us at tips@codeoftheweek.com. Be sure to include instructions and source code. For each tip received which gets published we will pay you $10 to $25 US Dollars.
In this issue we discuss how access the Outlook calendar appointments using the Outlook Object Model.
If you have any questions about using this module, let us know at questions@codeoftheweek.com
This class allows you to access the Outlook appointments which appear in the default calendar. The full object model for the AppointmentItem object is available at http://msdn.microsoft.com/library/psdk/cdo/_olemsg_appointmentitem_object.htm
The basic usage of this class is to set the StartDate and EndDate properties to control which appointments are returned and then call the GetAppointments method. This method will retrieve a collection with the appointments that start between StartDate and EndDate.
Public Property Let StartDate(dStart As Date) Public Property Get StartDate() As Date
The beginning of the date range used to determine with appointments will be returned by the GetAppointments method.
Public Property Let EndDate(dEnd As Date) Public Property Get EndDate() As Date
The end of the date range used to determine with appointments will be returned by the GetAppointments method.
Public Sub GetAppointments(colAppt As Collection)
This is the method that does most of the work. A collection object needs to be passed to hold all the appointments between the date range StartDate and EndDate. The objects which will be stored in the collection colAppt are AppointmentItem objects. You can refer to the Outlook Object Model documentation for complete details at http://msdn.microsoft.com/library/psdk/cdo/_olemsg_appointmentitem_object.htm
The Count property of the collection can be used to determine how many appointments were returned.
The appointments read by this method are the ones in the default calendar folder.
This sample shows how to use the cOutlookCalendar class by retrieving all appointments between 9/1/2000 and 9/30/2000. This sample just prints out the starting date/time, duration (in minutes) and the subject of the appointment.
Dim oc As New cOutlookCalendar Dim colAppt As New Collection Dim oAppt As AppointmentItem oc.StartDate = "9/1/2000" oc.EndDate = "9/30/2000" oc.GetAppointments colAppt ' Prints out the start time, duration and subject of the appointment ' Duration is in minutes For Each oAppt In colAppt Debug.Print oAppt.Start, oAppt.Duration, oAppt.Subject Next
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0129.html