|
|
|||
| Basic Outlook Printer Friendly Version | |||
|
|
Working with Outlook items, folders, recipients; dealing with security; writing event handlers | ||
| Topic | |||
|
|
Strange behaviour with Restrict on Shared Folder
Hi All, I hope that someone hasn't posted about this before but I am using Outlook 2003 VBA to find all appointments after a certain date and delete them. When I run this code on my own appointments it finds all the appointments fine and deletes them. However, when I run it on a shared folder - it doesn't find all of the appointments (identical to those in my folder) on the first run. It seems to miss the last 2 appointments. If I run the function again, it finds one of the 2 extra ones and then if I run it again, it finds the last one. Have I missed something? Heres my code: strRestriction = "[End] >='" & Format$(datStart, "dd/mmm/yyyy ") & " 00:00'" Dim oResItems Set oResItems = oItems.Restrict(strRestriction) oResItems.Sort "[Start]" Dim oAppt As AppointmentItem For Each oAppt In oResItems If InStr(1, oAppt.Categories, G_Flight_Category) > 0 Then 'Delete all appointments with category Flights oAppt.Delete intCount = intCount + 1 End If Next Have I made a glaring error somewhere? Laurie LaurieN 07-Nov-2009 12:57 |
||
|
|
Sue Mosher
07-Nov-2009 14:07
Yes, the problem is in deleting inside a For Each loop. Instead, use a downcounting loop: cnt = oResItems.Count For i = cnt to 1 Step -1 Set oAppt = oResItems.Item(i) oAppt.Delete Next The problem would exist regardless of the folder. I can't explain why you might not have seen it in your own folder. |
||
|
|
Anonymous
08-Nov-2009 10:19
That was it - strange though that it always worked on my calendar! I should have thought about it as I had already come across the 'delete from the end' method with removing multiple items from a list box earlier on this project! Thanks Sue! |
||
|
|
|||
