Toxter

Hello everyone,

I'm developing Outlook 2003 addin.

I'm using a copy of MailItem temporarily which I need to delete later.

I can do that by calling MailItem.Delete() method.

When I invoke Delete() method, Outlook stores it in 'Deleted Items' folder .

I would like to delete MailItem without Outlook storing it to 'Deleted Items' folder (like Shift+Delete).

Is this possible

Thanks.



Re: Visual Studio Tools for Office Delete Outlook MailItem?

Sue Mosher - Outlook MVP

Try this: Use the Move method to move the item to the Deleted Items folder, getting a reference to the item that Move returns and then deleting that moved item.



Re: Visual Studio Tools for Office Delete Outlook MailItem?

Toxter

Hello Sue,

This tip works with one little change:

after moving a MailItem to 'Deleted Items' folder, moved item needs to be saved first (by invoking MailItem.Save()) and

after that it can be deleted (by invoking MailItem.Delete()).

Without saving first, it wouldn't be deleted(I'm not sure why).

I just thought I need to write this in case someone else has a same problem.

Thanks again for your help.





Re: Visual Studio Tools for Office Delete Outlook MailItem?

KateCooper

Having similar problems but only with 2007 outlook.....

2003 this code works 2007 it throws an exception.. Message

cannot delete .....

Try

GetCurrentMailItem.Delete()

Catch ex As Exception

MsgBox("About To Delete Emails -" & ex.Message)

End Try





Re: Visual Studio Tools for Office Delete Outlook MailItem?

Sue Mosher - Outlook MVP

Is there anything special or significant about GetCurrentMailItem Does another object have a reference to the same item Have you checked to see if you can delete the item manually



Re: Visual Studio Tools for Office Delete Outlook MailItem?

KateCooper

Sue,

This is the whole code segment...

Public TheCurrentInspector As Outlook.Inspector = Nothing

TheCurrentInspector = TheOutlookApp.ActiveInspector

Public Function GetCurrentMailItem() As Outlook.MailItem

Return TheCurrentInspector.CurrentItem

End Function

GetCurrentMailItem.Delete()

Not positive about another object having a reference... (Legacy Code-not mine)

don't think so since it is used by the email author alone (one author)

Can delete the item manually no problem there....

If I put a Try...Catch in with Exception I get a message (from outlook ) cannot delete item...

Works fine on 2003 crashes on 2007....

Thanks

-J