• Subject: Deleting a draft of an email
  • Author: kevotheclone
  • Date: 12 Nov 2009
  • References:
I've got a Outlook COM Addin that appends text to an email's Subject and Body when a specific button is clicked. One problem I encountered is with a new email, if the user types anything into the subject line before clicking the button I am unable to read the subject's text because the email has not been saved. Without being able to read the subject's text, I can't append text, only blindly overwrite it. To resolve this I check the MailItem.Saved property and if it's not already saved I save it with the MailItem.Save() method. This works well and by itself is not a problem. If Not miCurrent.Saved Then miCurrent.Save strEntryID = miCurrent.EntryID End If ' Not miCurrent.Saved However after I save the email there's a copy in the user's Draft folder. If the user Sends the email or Deletes the email it will be automatically deleted from the Drafts folder, but if the user Closes the email and answers "No" to "Do you want to save changes?" the email remains in their Drafts folder. So my problem is trying to delete the email. I've saved the EntryID of the email right after I save it and I know it's the correct EntryID via debugging MsgBoxes. I've tried deleting the email within it's Close event, and yes "miCurrent" is declared in my Class "WithEvents": Private WithEvents miCurrent As Outlook.MailItem Private Sub miCurrent_Close(Cancel As Boolean) miCurrent.Delete End Sub ' miCurrent_Close(Cancel As Boolean) I've also tried deleting the email from the Inspector's Close Event, and yes the "mailInspector" is declared in my Class "WithEvents": Public WithEvents mailInspector As Outlook.Inspector Private Sub mailInspector_Close() Dim nsMapi As Outlook.NameSpace Dim miToDelete As Outlook.MailItem Dim fldrDeleted As Outlook.MAPIFolder Set nsMapi = Outlook.GetNamespace("MAPI") Set miToDelete = nsMapi.GetItemFromID(strEntryID) MsgBox miToDelete.Subject ' For debugging to see if I've got the correct MailItem miToDelete.Delete End Sub ' mailInspector_Close() In both cases I get: Run-time error: '-1698430712 (9ac40108)': Unable to complete the command. I've read this thread, which gave me some of the ideas, to work with but the problem still isn't resolved. How can you reliable delete a MailItem on a Close event? Or is there another Object/Event that I should use? http://groups.google.com/group/microsoft.public.office.developer.outlook.vba/browse_thread/thread/e5702708a8099746/a321f5a9bb627e0?hl=en&q=How+do+I+delete+draft+emails%3F Thanks in advance for any assistance anyone can provide! We're using Outlook 2003, build 11.8313.8221 SP3
12 Nov 2009Deleting a draft of an email.kevotheclone
13 Nov 2009\ Re: Deleting a draft of an email.Ken Slovak - [MVP - O...
13 Nov 2009   \ Re: Deleting a draft of an email.kevotheclone
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)