Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2005

Tip: Looking for answers? Try searching our database.

Deleting items in public folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maria Jensen - 27 Sep 2005 11:22 GMT
Hi there,

I have a curious situation. I want the user to pick a folder, do stuff with
each item in the folder and then delete the item (not the folder). When I
try this, it seems that I only get through half the folder, then it exits.
That means that only half the messages are deleted. If I just run through
the folder without doing Item.Delete, my code runs through all items.

Now, the folder chosen is a public folder - I have a feeling that perhaps
that has something to do with this problem.

Can anyone help?

This is my code:

Set oApp = New Outlook.Application

Set oNamespace = oApp.GetNamespace("MAPI")

Set oFolder = oNamespace.PickFolder

If Not oFolder Is Nothing Then

   MsgBox "No of mails: " & oFolder.Items.Count

   For Each Item In oFolder.Items

       ---- Doing stuff -----

       Item.Delete

   Next

End If
neo [mvp outlook] - 27 Sep 2005 13:51 GMT
The problem is within the For/Each loop.  Basically it is going to process
every other item because the instant a delete is issued, the items
collection is reordered.  You need to rewrite the loop so it process the
items in a descending order.

> Hi there,
>
[quoted text clipped - 31 lines]
>
> End If
Maria Jensen - 27 Sep 2005 14:49 GMT
Processing the items in descending order solved the problem. Thank you very
much

:-) Maria

> The problem is within the For/Each loop.  Basically it is going to process
> every other item because the instant a delete is issued, the items
[quoted text clipped - 36 lines]
>>
>> End If
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.