>Hey--
> I'm trying to write a program that will go through users email accounts (Microsoft Outlook) and delete messages from the Inbox and Deleted Items folders. So far, I have written this code:
>
> loapp=CREATEOBJ('Outlook.Application')
> loSpace=loapp.getnamespace('MAPI')
> mmailbox="Mailbox - "+ALLT(GETE('name')) &&the way that we access specific users accounts
> loInbox=loSpace.GetDefaultFolder(6)
>
> mdelete=MESSAGEBOX("Do you want to delete the messages in the Inbox?",292)
> DO CASE
> CASE mdelete=6
> FOR EACH item in loInbox.items
> item.delete()
> ENDFOR
> CASE mdelete=7
> ENDCASE
>
>which does go through the inbox and begins to delete messages, but it doesn't delete all of them, it always leaves 2 or 3. Just wondering if there is some hole in this code that is causing that and if there is a delete all option or something of the sort for Outlook in VFP.
>
>Thanks
>
>Kent Floros
>Ripon Community Printers
You should start at the end of the collection to the start:
For x=loInbox.Items.Count To 1 Step -1
In most collections deleting items with a for each causes the item pointer to be out of sync with the loop.