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 send an email (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 going to 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. I was trying:

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

I believe the issue is in the line where I'm trying to set the msg variable. I have tried all sorts of things but can't get it to work. Any suggestions would be very welcome.