Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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 log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...


Exchange Server and Outlook Whitepapers Protecting (You and) Your Data with Exchange Server 2007

StoreVault SnapManagers for Microsoft Exchange and SQL Server

Related Events Storage Consolidation for Your Microsoft Applications: Reducing Cost and Complexity

The Myths & Truths of Email Management with SharePoint

Top 10 Email Security Challenges and Solutions

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing