Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2003

Tip: Looking for answers? Try searching our database.

How do I programmatically tell Outlook to not save a copy of a message in the Sent Items folder and Deleted Items folder when forwarding and then deleting a message?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary - 16 Sep 2003 00:47 GMT
Hello,

I have an add-in VB 6 COM program that forwards emails using Outlook
2000. When a message is forwarded, it is sent to another email address
and then deleted. This is fine and works great.  However, after
running the VB 6 code (in a VB Add-in project), I end up with a copy
of the message in my Sent Items folder and another copy of the same
message in the Deleted Items folder.  Besides turning off the option
{Tools | Options | Preferences Tab | E-mail Options | uncheck Save
copies of messages in Sent Items folder), can this be done in code on
a per email basis and in code?  I also need a way for Outlook to not
move a copy of the message to the Deleted Items folder.  How can this
be programmatically done using the Outlook Object model?

In other words, when my COM Add-in program is running and if the user
selects to forward the email to another email address, I would like to
forward the email to another email address without putting a copy of
the message in the Sent Items folder or a copy of the message in the
Deleted Items folder. Normally, Outlook does this, but I am looking
for a way so that it doesn't do it (in the case when my add-in is
running).

The ideal solution would be to turn off the "Save copies of message in
Sent items folder" when an email is being forwarded with my add-in
program and then turn it back on when it is done. Likewise, my add-in
program would also need to delete the item in the Deleted items folder
or find a way to tell Outlook not to save a copy of the message in the
Deleted Items folder.

Does anyone know how to do this? I seem to remember reading that the
properties in (Tools | options | E-mail options) are not
programmatically available, but I could be wrong.

Thanks.
Sue Mosher [MVP] - 16 Sep 2003 01:38 GMT
Take a look at the MailItem.DeleteAfterSubmit property.
Signature

Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
    Microsoft Outlook Programming: Jumpstart
    for Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx 

> Hello,
>
[quoted text clipped - 9 lines]
> move a copy of the message to the Deleted Items folder.  How can this
> be programmatically done using the Outlook Object model?
Gary - 16 Sep 2003 17:58 GMT
Hello,

Thanks for the help. I appreciate it.

Your suggestion worked except that now when I delete the original
message, it is moved to the deleted items folder, which isn't what I
want.  If I don't delete the original message, it remains in my inbox
folder. I would like to delete the original message after it is
forwarded and to not have a copy of the message in my Deleted Items
folder.

Here is the code block I am using. (In my add-in VB project I display
a nonmodal form with a command button that the user clicks to forward
the email message – not a userform in Outlook).  And this works great
except the pesky problem.  Possibly, I am doing something wrong.

Private Sub cmdPersonal_Click()
Dim myolapp As outlook.Application
Dim myNameSpace As outlook.NameSpace
Dim myFolder As outlook.MAPIFolder
Dim myItem As outlook.MailItem
Dim FWDItem As outlook.MailItem
Dim strInput As String
Dim myRecipient As outlook.Recipient

On Error GoTo cmdPersonal_Click_Err:   

StartPrompt:
 
       strInput = InputBox("Enter email address to where you want to
forward this email message?", "Forward", "", 4755, 6000)
   
   If strInput = "" Then
   
   
       If MsgBox("Please enter an email address to where you would
like to forward this email." & vbCrLf & vbCrLf & "Email address is
blank or Cancel was clicked." & vbCrLf & vbCrLf & "Would you like to
try again?", vbYesNo) = vbYes Then
             GoTo StartPrompt
       Else
           Exit Sub
       End If
   Else
       
       Set myolapp = CreateObject("Outlook.Application")
       Set myNameSpace = myolapp.GetNamespace("MAPI")

       
       
       

       Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
       Set myItem = myolapp.ActiveInspector.CurrentItem  ‘an email is
already opened
       Set FWDItem = myItem.Forward
       Set myRecipient = FWDItem.Recipients.Add(strInput)
       
       FWDItem.DeleteAfterSubmit = True ‘New code as suggested by
Sue. Thanks!
       myItem.DeleteAfterSubmit = True ‘extraneous? Trial and error
to see if it works.
       FWDItem.Send ‘now send the message
       
       'delete the original message
       ClosedByProgram = True ‘set flag
       myItem.Delete
       ‘clear flag
       ClosedByProgram = False
       Unload Me
   End If
cmdPersonnel_Click_Exit:
   On Error Resume Next
   If Err <> 0 Then Err.Clear
   Exit Sub
cmdPersonal_Click_Err:
   MsgBox Error$
   Resume cmdPersonnel_Click_Exit
End Sub

So, as you can tell, I have 2 object variables: myItem pointing to the
original email message and FWDItem pointing to the forwarded email
message.  After adding your suggestion      
FWDItem.DeleteAfterSubmit = True that worked great by not saving a
copy in the Sent Items folder.  However, I still end up with a copy of
the email in my Deleted Items folder (as a result of the line
myItem.delete).

Next, I commented out the line myItem.delete to see what would happen.
The message gets forwarded but the original message remained in my
inbox, which isn't what I wanted. So, that is the reason for the line
myItem.Delete. As soon as this line executes, a copy of the message is
put into my Deleted Items box (which is normal I guess). I would like
to unconditionally and permanently delete the original message in the
inbox. The manual way is to hold down the Shift key and push Delete,
but I am doing this through code.

Thanks again for all your help.  Maybe there is another property that
I am missing. Any help is most appreciated.  I also want to thank
everyone who has helped me.
Sue Mosher [MVP] - 16 Sep 2003 18:48 GMT
You would need to either delete from the Inbox, then delete it from Deleted Items or use CDO to perform the deletion, which will make it permanent in one step -- sample code at http://www.outlookcode.com/codedetail.aspx?id=41 

Signature

Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
    Microsoft Outlook Programming: Jumpstart
    for Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx 

> Your suggestion worked except that now when I delete the original
> message, it is moved to the deleted items folder, which isn't what I
[quoted text clipped - 7 lines]
> inbox. The manual way is to hold down the Shift key and push Delete,
> but I am doing this through code.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.