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

Deleting all outlook contacts.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 17th 09, 01:46 PM posted to microsoft.public.outlook.program_vba
daxriders
external usenet poster
 
Posts: 1
Default Deleting all outlook contacts.

Hi...

i've been trying to delete all my outlook contacts to update them with a DB.
The problem is that there are always some contacts left?!?

Anyone knows why and how to solve this issue?

here's my code(vb.net)

Dim olApp As New Outlook.Application
Dim olNamespace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder =
olNamespace.GetDefaultFolder(Outlook.OlDefaultFold ers.olFolderContacts)

'Do While olFolder.Items.Count 0 this option doesnt work either
For Each olItem As Outlook.ContactItem In olFolder.Items
olItem.Delete()
Next
'Loop

  #2  
Old July 17th 09, 02:02 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Deleting all outlook contacts.

Never delete inside a For Each ... Next loop. Each deletion resets the
index. Instead, use a down-counting loop. Also, you should always get each
object separately, rather than using dot-operator expressions like
olFolder.Items.Count:

myItems = olFolder.Items
count = myItems.Count
For i = 1 to Count Step -1
olItem = myItems.Item(i)
olItem.Delete()
Next

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"daxriders" wrote in message
...
Hi...

i've been trying to delete all my outlook contacts to update them with a
DB.
The problem is that there are always some contacts left?!?

Anyone knows why and how to solve this issue?

here's my code(vb.net)

Dim olApp As New Outlook.Application
Dim olNamespace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder =
olNamespace.GetDefaultFolder(Outlook.OlDefaultFold ers.olFolderContacts)

'Do While olFolder.Items.Count 0 this option doesnt work either
For Each olItem As Outlook.ContactItem In olFolder.Items
olItem.Delete()
Next
'Loop



  #3  
Old July 17th 09, 01:57 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Deleting all outlook contacts.

When deleting items in a collection and using a For loop you mess with the
loop index each time you delete an item and end up deleting half the items
in each pass. Use a count down For loop for that:

For i = oFolder.Items.Count To 1 Step -1

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"daxriders" wrote in message
...
Hi...

i've been trying to delete all my outlook contacts to update them with a
DB.
The problem is that there are always some contacts left?!?

Anyone knows why and how to solve this issue?

here's my code(vb.net)

Dim olApp As New Outlook.Application
Dim olNamespace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder =
olNamespace.GetDefaultFolder(Outlook.OlDefaultFold ers.olFolderContacts)

'Do While olFolder.Items.Count 0 this option doesnt work either
For Each olItem As Outlook.ContactItem In olFolder.Items
olItem.Delete()
Next
'Loop


 




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
Retrieve contacts after deleting Outlook Exchange account My-Dog-Ate-My-Contacts Outlook - Using Contacts 2 January 25th 08 06:28 PM
Why is Outlook auto-deleting my contacts? JG@RRC Outlook - Using Contacts 1 October 5th 07 11:28 PM
My Outlook/Hotmail interface keeps deleting contacts. Kelley Turley Outlook - Using Contacts 0 November 22nd 06 12:19 AM
Outlook 2003...prevent deleting contacts? Melissa Outlook - General Queries 5 September 30th 06 12:57 AM
Deleting contacts from Outlook 2003 OntCan Outlook - Using Contacts 3 May 12th 06 03:50 PM


All times are GMT +1. The time now is 06:53 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.