![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |