Delete ContactItems without going into DeletedItems/Trashcan

F

Fredrik Nelson

Hi,

I have a smal program that add contacts from a database to a Contact Folder
i Outlook
I start with deleting all contacts that have a certian attribute and
everything else works fine..
The bad thing is that the deleted items show up in the trashcan whish fill
up quite fast that way so the code below works but not quite as good as I
want.

Does any one know how to delete items without having them go inte the
trashcan?

Sub Deletetems()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myRestrictItems As Outlook.Items
Dim myItem As Outlook.MailItem
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItems = myFolder.Items
Set myRestrictItems = myItems.Restrict("[ReferredBy] <> ''")
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Delete
Next
End Sub



/Fredrik
 
K

Ken Slovak - [MVP - Outlook]

When you delete using the Outlook object model the deleted items always go
to the Deleted Items folder. No way around that. If you use CDO 1.21 or
Redemption or Extended MAPI code you can delete an item without it's being
added to Deleted Items.

You could monitor the ItemAdd event on the Items collection of the Deleted
Items folder. If a new item is added that's a contact (you can add a user
property to the ones you delete for id purposes) then delete it from Deleted
Items. It's a hack but it works and only uses Outlook object model code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top