views:

1581

answers:

3

Hello all, I am looking for a way to permanently delete a MailMessage from Outlook 2000 with VBA code. I'd like to do this without having to do a second loop to empty the Deleted items.

Essentially, I am looking for a code equivalent to the UI method of clicking a message and hitting SHIFT+DELETE.

Is there such a thing? TIA!

+1  A: 

Try moving it first then deleting it (works on some patchs in 2000) or use RDO or CDO to do the job for you (you will have to install them)

  Set objDeletedItem = objDeletedItem.Move(DeletedFolder)
  objDeletedItem.Delete

CDO way

Set objCDOSession = CreateObject("MAPI.Session")
objCDOSession.Logon "", "", False, False
Set objMail = objCDOSession.GetMessage(objItem.EntryID, objItem.Parent.StoreID)
objMail.Delete

RDO

set objRDOSession = CreateObject("Redemption.RDOSession")
objCDOSession.Logon 
set objMail = objRDOSession.GetMessageFromID(objItem.EntryID>)
objMail.Delete

You could also mark the message first before you delete it and the loop through the deleted items folder and find it an dthe call delete a second time. Mark it using a Userproperty.

objMail.UserProperties.Add "Deleted", olText
objMail.Save
objMail.Delete

loop through you deleted items look for that userprop

 Set objDeletedFolder = myNameSpace.GetDefaultFolder(olFolderDeletedItems)
    For Each objItem In objDeletedFolder.Items
        Set objProperty = objItem.UserProperties.Find("Deleted")
        If TypeName(objProperty) <> "Nothing" Then
            objItem.Delete
        End If
    Next
76mel
I'd rather not go CDO or RDO, cuz my whole point here was to reduce code complexity, and I'd rather not go introducing all new dependencies. The second is basicaly what I am doing now. I first do (pseudo): for each msg in inbox msg.delete '// moves to deleted itemsnextfor each msg in deletedItems msg.delete '// deletes permanentlynextwhereas what i'd like to do, is something like: for each msg in inbox msg.delete(permanent = true)next
eidylon
There is no such method in 2000. You will have to create your own function in VBA. What is wrong with the move-delete or your loop ? is it performance ?
76mel
Nothing inherently "wrong" with it, i was just looking for a way to do it more cleanly than relying on two loops.Thanks anyway though.
eidylon
A: 

You can use the following approach, basically you delete all of your email messages as you are currently doing, then call this one line to empty the deleted items folder. The code is in jscript, but I can translate if you really need me to :)

var app = GetObject("", "Outlook.Application"); //use new ActiveXObject if fails

app.ActiveExplorer().CommandBars("Menu Bar").Controls("Tools").Controls('Empty "Deleted Items" Folder').Execute();
Marcus Pope
A: 

Simplest solution of all, similar to the first way:

  FindID = deleteme.EntryID
  deleteme.Delete
  set deleteme = NameSpace.GetItemFromID(FindID)
  deleteme.Delete

Do it twice and it'll be gone for good, and no performance killing loop. (NameSpace can be a particular namespace variable, if not in the default store.) Note this only works if you don't delete across stores, which can change the EntryID or remove it entirely.

SilverbackNet