Code to automatically delete message after sending

Status
Not open for further replies.

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I have developed code that does various things including saving incoming and outgoing emails in MSG format in a standard file naming convention in a folder the user chooses either from browsing to the folder or selecting it from a drop down list on a userform. I have set up a userform that automatically opens when you press the send button (uses Application_ItemSend to do this). On the userform that opens I have several buttons that do different things. One of them saves the email in MSG format in a chosen folder, one simply sends the email with a copy of the email being put in the Sent Items folder and the third button sends the email and deletes it. It is this third button that is giving me trouble as I can't get it to work. Any suggestions on the code I should be using bearing in mind the code will be run from a button on a userform and the userform has been opened using Application_ItemSend.

Thanks for your help
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I tried but couldn't get it to work probably because I got the code wrong. I tried

sub commandbutton17_click ()
dim msg as outlook.mailitem
msg.deleteaftersubmit = true
msg = nothing
End sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You need to set the msg variable to the item that is going to be send.
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Sorry but I have very little coding experience. Can you provide some further guidance on how to do this
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You already have two buttons doing something successfully with the message. Simply copy the code from there that references the message.
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Doh! copied the code as suggested and it works fine now
 
Status
Not open for further replies.
Top