Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook deleting flagged mail

Status
Not open for further replies.

jdrawmer

Programmer
Dec 1, 2006
25
GB
Hi Guys,

I've got some outlook code which manipulates emails, saves them elsewhere, and now i am required to simply tick a box thats says 'delete original' which basically, will delete the original from the inbox.

My method behind this was to flag the email as 'olFlagMarked' and then a simple statement that runs through the inbox, deleting flagged emails. I tried this because the approach of simply deleting the email, kept throwing up an 'Outlook cannot delete this item' error, and i'm getting that same error now. I just wanna know why.

Code:
    Dim ns As NameSpace
    Dim inbox As MAPIFolder
    Dim mail As mailItem
    
    Set ns = Application.GetNamespace("MAPI")
    Set inbox = ns.GetDefaultFolder(olFolderInbox)
    
    For Each mail In inbox
        If mail.FlagStatus = olFlagMarked Then
            mail.Delete
        End If
    Next

Thats basically the code i've attempted to use, and the same error crops up everytime. Whether i run it from a function, directly after the other code, or in a seperate macro altogether... Hmmm

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top