PDA

View Full Version : Help with deleting items If/Then



serq
05-14-2018, 11:07 AM
Hi all-

I have a script that forwards message with some information and then deletes the message. It works, except that I don't want it to delete messages if the message is currently in the deleted items folder. I can't seem to make this work. How do I write the statement "If message is in deleted items, then do not delete. Else, delete"?

Alternately, is there an easy way to get the email header info so that can be forwarded along as well? The reason for leaving the email in deleted items is so that we can remote to the user and check out the header info if we need to.

Any help is much appreciated!!!

Thanks!

skatonni
05-14-2018, 02:21 PM
Normally your code would be included but this should be adaptable to whatever you have.


Public Sub LeaveInDefaultDeletedItemsFolder()

Dim objItem As mailItem

Set objItem = ActiveExplorer.Selection.item(1)

If objItem.Parent <> Session.GetDefaultFolder(olFolderDeletedItems) Then
MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Put code to delete here."
Else
MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Do not delete."
End If

End Sub


Public Sub LeaveInAnyFolderName()

Dim objItem As mailItem

Set objItem = ActiveExplorer.Selection.item(1)

Debug.Print objItem.Parent

If objItem.Parent <> "Deleted Items" Then
MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Put code to delete here."
Else
MsgBox "The folder is: " & objItem.Parent & vbCr & vbCr & "Do not delete."
End If

End Sub