Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


January 2001

Deleting Recurring Appointments


RSS
Subscribe to Windows IT Pro | See More Visual Basic (VB) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

In the December 2000 Outlook VBA on Demand, I demonstrated how to set up a system for purging specific folders on demand. This time, I dig deeper into the notion of deleting items from folders. You'll learn how to remove appointment items, including recurring appointments, and how to purge only items that occurred before a specific date.

First, you need to choose a date property on which to build the filter. The logical property to use in a calendar folder is End. Suppose a calendar folder includes an event that begins February 25, 2001, and ends March 4, 2001. You want to purge all items older than March 1. If you use the Start date as the property for your filter criteria, the purged items will include the 8-day event because its Start date occurs before March 1. However, if you use the End property, the item will remain on the calendar because the End date is more recent than your March 1 cutoff date.

The PurgeCalendarFolder() function, which you see in Listing 1, takes a MAPIFolder object as its single argument and returns a string that reports the number of items the function removed. You'll need to call PurgeCalendarFolder() from another procedure, such as the December column's CleanFolders subroutine. For testing, you can obtain a TestPurgeCalendarFolder() subroutine from the Windows 2000 Magazine Web site. (Go to http://www.win2000mag.com, enter 16207 in the InstantDoc ID text box, and go to the Article Information box to download the 16207.zip file.) This subroutine lets you pick a folder from the Select Folder dialog box. Notice that the PurgeCalendarFolder() function uses the DefaultItemType property to check the type of folder, then proceeds only if the folder is a calendar folder (i.e., a folder containing appointment items).

The two statements below cause the collection of items in the folder (i.e., colItems) to treat individual recurrences as separate appointments. Therefore, you can purge older instances of recurring appointments while leaving more recent instances in the folder. The IncludeRecurrences property is effective only if you use the Start property to sort the collection, as follows:

colItems.Sort "[Start]"
colItems.IncludeRecurrences _
  = True

The GetRestrictDate() function, (Web Listing 1) which you can obtain from the Windows 2000 Magazine Web site, displays an input box in which the user can type a date. Alternatively, to instruct Microsoft Outlook to delete all items in the folder, the user can leave the box blank. If the user enters information other than a date, the function calls itself until the user provides valid input. When you use such recursive functions, be sure to provide a method for the user to escape the loop—in this case, by leaving the box blank or providing a valid date.

The PurgeCalendarFolder() function uses the date that GetRestrictDate() returns to build a restriction on the colItems collection. For example, if a user enters "9/30/2000", the function builds the following string, which the Restrict method will use:

[End] < "Sep 30, 2000"

This example highlights an Outlook syntax quirk: The Restrict and Find methods won't work with a date literal, such as #9/30/2000#. Instead, they need a string.

After you apply the restriction to the colItems collection to get a new collection, colOldItems (containing only the older items), the PurgeCalendarFolder() function operates essentially the same way that the PurgeFolder() function in the December column operates—it deletes all the items in the collection.

End of Article



Reader Comments
Tanks for the article.
I am interested to updating appointments is my calendar with the category "Test" between two days, Start and End. First I must delete all appointments between the two days and then add the new ones. That is not for shore there is one to delete because it don’t exist one for that day. How do I do? I can add but not delete in a proper way.
Thanks.

Sten-Olov Vikström March 03, 2003


Sten-Olov, see http://www.outlookcode.com/d/finddate.htm for details on how to build search strings that locate items on particular dates.

Sue_Mosher August 19, 2004 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Exchange Server and Outlook Whitepapers Take Control of Your Email: Understand the Business Reasons for Email Storage Management

Continuous Data Protection and Recovery for Microsoft Exchange

Related Events WinConnections and Microsoft® Exchange Connections

Check out our list of Free Email Newsletters!

Exchange Server and Outlook eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

The Expert's Guide for Exchange 2003: Preparing for, Moving to, and Supporting Exchange Server 2003

Related Exchange Server and Outlook Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Exchange & Outlook UPDATE eNewsletter
News, strategies, products, and developments in Exchange Server and Outlook messaging.

Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement