Deleting all outlook contacts.

  • Thread starter Thread starter daxriders
  • Start date Start date
Status
Not open for further replies.
D

daxriders

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.OlDefaultFolders.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
 
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

"daxriders" <daxriders> wrote in message

news:27F41AFD-A65E-4615-B545-0871E8A58F69@microsoft.com...
> 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.OlDefaultFolders.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
>
 
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

"daxriders" <daxriders> wrote in message

news:27F41AFD-A65E-4615-B545-0871E8A58F69@microsoft.com...
> 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.OlDefaultFolders.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
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
B Outlook 2013 erratically deleting original file that is attached Using Outlook 0
D Outlook 2016 Deleting emails without affecting folder structure - Outlook Office 365 Using Outlook 3
N Saving And Deleting Outlook Attachments with Unknown Error Message Outlook VBA and Custom Forms 1
C Outlook is permanently deleting deleted items (purging) Using Outlook 0
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
W Deleting Emails from the Server in Outlook 2016 Using Outlook 2
B Outlook not deleting messages from server Using Outlook 0
V Outlook 2013 deleting email text when sent Using Outlook 11
D Outlook 2013 Deleting all my messages Using Outlook 9
R Deleting Attachments(embedded) in Outlook 2013 Using Outlook 10
W Outlook deleting emails Using Outlook 5
O Outlook 2013 deleting emails randomly Using Outlook 0
G Deleting AOL Emails form Outlook 2010 or 2013 Using Outlook 1
L Outlook 2013 IMAP account is deleting e-mails from my inbox - help!!! Using Outlook 3
S Outlook 2010 is not deleting mail from my server once downloaded Using Outlook 2
G Outlook 2003 - automatically deleting inbox msg after reply Outlook VBA and Custom Forms 1
Fozzie Bear Accepted Zoom Invites deleting without going into Default Calendar - Office 2016 Mac Using Outlook 3
J Autoreply email recieved from specific sender after deleting some text from body. Using Outlook 0
M Deleting attachments does not reduce file size Using Outlook 0
L Deleting Office 365 calendar appt w/o emailing invitees Using Outlook 3
R Deleting emails from storage folder Outlook VBA and Custom Forms 1
R Deleting Synchronisation of Old Accounts Using Outlook.com accounts in Outlook 0
T Deleting duplicate emails Using Outlook 2
W Deleting Sent Task Email, Deletes the task from my list Using Outlook 1
M Adding Macro to populate "to" "subject" "body" not deleting email string below. Outlook VBA and Custom Forms 5
L OL 2016 contact: is there a way to prevent an admin from mistakenly deleting a contact? Using Outlook 1
B Deleting multiple accounts Using Outlook 1
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
P Deleting items in folders doesnt send them to deleted items! Using Outlook 4
Rupert Dragwater Deleting email from Deleted Items does not work Using Outlook 0
B Deleting old Stream_autocomplete and other files Using Outlook 1
skylark53 Loss of default format on deleting signature Using Outlook 5
P deleting old UDP items in tasks Outlook VBA and Custom Forms 3
D After Moving or Deleting Open Item - Meeting Requests Using Outlook 4
J Deleting Email from Exchange Server Using Outlook 2
T Deleting iCloud Synced Contacts Exchange Server Administration 2
N Messages still in 'Deleted items' folder even after deleting! Using Outlook 2
N Deleting Duplicate Calendar Entires Outlook VBA and Custom Forms 2
S Deleting Personal folder and IMAP account PST files Using Outlook 0
C Is there a way to prompt a user before deleting an item? BCM (Business Contact Manager) 4
D Deleting internet calendar on one computer removes it from all computers Using Outlook 2
B Deleting Nested Attachments Using Outlook 2
Commodore Deleting folders or feeds when deleting from default RSS Feeds structure? Using Outlook 7
K Clearing/Deleting all Public Folders through VBA Using Outlook 3
S Deleting Custom Fields Using Outlook 4
R Deleting one email in a conversation deletes all Using Outlook 6
O Inbox Search Results won't update when deleting or moving an email Using Outlook 12
B How to completely and permanently deleting a POP3 Account in 2010 Using Outlook 9
P Printing, pasting & deleting issues Using Outlook 4

Similar threads

Back
Top