PC Review


Reply
Thread Tools Rate Thread

Deleting contacts via code

 
 
John
Guest
Posts: n/a
 
      19th Jun 2005
Hi

I am trying to delete contacts based on a condition via code. I am using the
below code. It is vb.net so syntax is slightly different than vba.

O = New Outlook.Application

F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

For I = 1 To ICount
oContact = DirectCast(F.Items.Item(I),
Outlook.ContactItem)
If InStr(oContact.Categories, "Clients") <> 0 then
oContact.Delete()
End If
Next I

The problem is that not all contacts are deleted. Presumably because when a
contact is deleted, F.Items.Item(I) does not mean anymore what it should.
Can someone tell me how can I reliably delete all contacts that fall into
the condition via code?

Thanks

Regards


 
Reply With Quote
 
 
 
 
Michael Bauer
Guest
Posts: n/a
 
      20th Jun 2005
Hi John,

in VBA youŽd write:

For I = lCount To 1 Step-1

i.e. the loop has to go backwards. Another approach, often faster, is
using Index=1 as long as the collection contains items:

While Collection.Count
Remove Collection(1)
Wend


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


John wrote:
> Hi
>
> I am trying to delete contacts based on a condition via code. I am
> using the below code. It is vb.net so syntax is slightly different
> than vba.
>
> O = New Outlook.Application
>
> F =
> O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
>
> For I = 1 To ICount
> oContact = DirectCast(F.Items.Item(I),
> Outlook.ContactItem)
> If InStr(oContact.Categories, "Clients") <> 0 then
> oContact.Delete()
> End If
> Next I
>
> The problem is that not all contacts are deleted. Presumably because
> when a contact is deleted, F.Items.Item(I) does not mean anymore what
> it should. Can someone tell me how can I reliably delete all contacts
> that fall into the condition via code?
>
> Thanks
>
> Regards



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem deleting contacts in Vista's windows Contacts?? =?Utf-8?B?Z3Nwb2ludGVy?= Windows Vista Mail 0 27th May 2007 05:44 PM
Will deleting a Form delete attached code? AND How to see ALL code in dB ? Mel Microsoft Access 2 30th Apr 2007 08:25 PM
Deleting contacts via code John Microsoft Outlook 1 20th Jun 2005 06:56 AM
Deleting contacts via code John Microsoft Outlook Discussion 1 20th Jun 2005 06:56 AM
Deleting contacts via code John Microsoft Outlook Calendar 1 20th Jun 2005 06:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.