delete/purge

  • Thread starter Thread starter RICK
  • Start date Start date
R

RICK

I'm having a heck of a time creating a delete/purge
command button. I know VBA for Excel, but Outlook is
foreign.
Could somebody please give me the commands for Delete
(currently selected message) and Purge Deleted Messages.

Thanks in advance!
 
The currently open item, if there is one, is
ActiveInspector.CurrentItem. The currently selected item or items are
in the ActiveExplorer.Selection collection. In either case once you
instantiate an item from that it would have a Delete method. That will
place the item in the Deleted Items folder.

Application.Session.GetDefaultFolder(olFolderDeletedItems) is the
Deleted Items folder. Once there you can get the Items collection of
the folder and iterate that collection with a down counting loop and
delete each member:

Dim oFolder As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim i As Long

Set oFolder =
Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oItems = oFolder.Items
For i = oItems.Count To 1 Step -1
oItems.Remove i
Next

If you use CDO 1.21 code you can delete items without sending them to
the Deleted Items folder. See www.cdolive.com/cdo5.htm for CDO 1.21
code samples.
 
Thanks Ken, I'll try this tonight.
I was wondering if the Delete method will work the same as
a Purge. The reason is I am pulling my email off a server
(fastmail.fm) using POP and it doesn't really get deleted
from there until a Purge command is sent.
I'll see what I can come up with tonight. Thanks again!
 
Delete will delete an item from a folder collection of Items, it won't
purge an item from a mail server. You would have to issue a command to
purge the item from the server in some way or other.
 
Whenever I use the menu bar, Edit/Purge Deleted Items,
that works. Isn't there a VBA equivalent of that?
 
No, unless you execute that button. You would get it as a
CommandBarButton object and use its Execute method.
 
Back
Top