A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Delete ContactItems without going into DeletedItems/Trashcan



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 12th 06, 03:33 PM posted to microsoft.public.outlook.program_vba
Fredrik Nelson
external usenet poster
 
Posts: 1
Default Delete ContactItems without going into DeletedItems/Trashcan

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


Ads
  #2  
Old May 12th 06, 08:20 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete ContactItems without going into DeletedItems/Trashcan

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Fredrik Nelson" wrote in message
...
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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add ContactItems to DLItem with VBS Christoph Fricke Outlook and VBA 8 May 10th 06 06:03 PM
How to Really Delete Sent items? [email protected] Outlook - General Queries 5 May 2nd 06 06:59 AM
how to delete an account T5 Outlook Express 4 March 29th 06 07:54 PM
can not delete ALROL Outlook Express 1 February 27th 06 03:36 PM
Delete is permanent?? Angyl Outlook - Using Forms 6 February 8th 06 10:35 PM


All times are GMT +1. The time now is 04:21 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.