Microsoft KB Archive/170789

= OL97: How to Retrieve All Recurring Appointments with Code =

Article ID: 170789

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Outlook 97 Standard Edition

-



This article was previously published under Q170789



SUMMARY
When writing programming code that retrieves a set of calendar appointments in Microsoft Outlook 97, you cannot retrieve all of the recurring appointments unless you set the IncludeRecurrences property to True for the collection of items.



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://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

In Outlook, you can create a recurring appointment, such as a meeting that occurs every Monday. Using Visual Basic Scripting Edition (VBScript) or Visual Basic for Applications automation code, you can use various methods to retrieve all or a subset of appointments from the Outlook Calendar. The Find and Restrict methods are typically used to retrieve a subset of all the appointments, such as the appointments for a particular month.

For example, assume a recurring appointment was originally created on the first Monday in January and that the appointment was set to recur on every Monday thereafter. If you use the Restrict method to retrieve all of the appointments in January, by default only the appointment for the first Monday is returned. If you use the Restrict method to retrieve the appointments in February, none of the recurring appointments are retrieved.

When programmatically referring to a group of appointments, these items are part of the Items Collection Object, which is a topic in the Vbaoutl.hlp file. In addition to the example in that topic, which returns all items in a folder, you can use the Find or Restrict methods to create a smaller collection (or subset) of appointments.

Once you specify the proper collection, use the IncludeRecurrences property to add all of the recurring appointments to the collection.

The following code example (with additional comments) is from the Vbaoutl.hlp file. It assumes you have already set up one recurring appointment in your calendar and that you have the Calendar folder selected: Sub GetRecurrences ' This example is VBA automation code and assumes you have the ' Outlook Object Library referenced. Dim myOlApp As Outlook.Application Set myOlApp = New Outlook.Application ' Set myItems to all of the items in the folder Set myItems = myOlApp.ActiveExplorer.CurrentFolder.Items ' Sort the collection based on the start date/time of the appt. myItems.Sort "[Start]" ' Set the IncludeRecurrences property to make sure all of the ' recurring appointments are also included in the collection. myItems.IncludeRecurrences = True ' Display one of the recurring appointments which have been included. MsgBox "The fifth instance of the recurring appointment " & _ "occurs on:" & myItems.Item(5).Start End Sub

