PC Review


Reply
Thread Tools Rate Thread

Deleting items in public folder

 
 
Maria Jensen
Guest
Posts: n/a
 
      27th Sep 2005
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


 
Reply With Quote
 
 
 
 
neo [mvp outlook]
Guest
Posts: n/a
 
      27th Sep 2005
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.

"Maria Jensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Maria Jensen
Guest
Posts: n/a
 
      27th Sep 2005
Processing the items in descending order solved the problem. Thank you very
much

:-) Maria

"neo [mvp outlook]" <(E-Mail Removed)> wrote in message
news:uche%(E-Mail Removed)...
> 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.
>
> "Maria Jensen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public Folder - Subfolders - items not visible to folder owners Annie1904 Microsoft Outlook Discussion 2 14th Jan 2008 09:51 AM
How do I stop other users deleting items in the public folder? Gazza Windows Vista General Discussion 3 7th Nov 2007 05:40 AM
Moving Outlook Mail Items from Deleted Items to Public Folder Phil Greenway Microsoft Outlook VBA Programming 1 2nd Feb 2004 03:59 PM
How do I programmatically tell Outlook to not save a copy of a message in the Sent Items folder and Deleted Items folder when forwarding and then deleting a message? Gary Microsoft Outlook VBA Programming 4 17th Sep 2003 05:47 PM
Deleting items in public folder with thousands of items "impossible" ?? Jesper Microsoft Outlook Contacts 2 14th Aug 2003 08:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:13 AM.