[AccessD] Deleting Outlook Contacts

Rocky Smolin rockysmolin at bchacc.com
Thu Sep 9 16:51:07 CDT 2010


No - I get an array index out of bounds error message 

However this works:

While olContacts.Count > 0
    olContacts.Item(1).Delete
    Set olContacts = olFolder.Items
    Me.txtProcessing = "Deleting Contacts..." & olContacts.Count
Wend


Rocky
 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Thursday, September 09, 2010 2:39 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Deleting Outlook Contacts

Does something like this work?
(assuming you have set olFolder to the contacts folder)

While olContacts.Count > 0
    olContacts.Item(0).delete
Wend


--
Stuart

On 9 Sep 2010 at 9:20, Rocky Smolin wrote:

> OK, here's what's working:
> 
>     ' delete all the current contacts
> DeleteAgain:
>     Set olContacts = olFolder.Items
>     If olContacts.Count = 0 Then GoTo DeleteDone:
>     Me.txtProcessing = "Deleting Contacts..." & olContacts.Count
>     Me.Repaint
>     Set olContactItem = olContacts.GetFirst
>     olContactItem.Delete
>     GoTo DeleteAgain:
> 
> DeleteDone:
> 
> It may not be optimized or the most elegant, but it works.  
> 
> Rocky
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky 
> Smolin Sent: Thursday, September 09, 2010 9:03 AM To: 'Access 
> Developers discussion and problem solving' Subject: Re: [AccessD] 
> Deleting Outlook Contacts
> 
> Steve:
> 
> " index the contact to be deleted "  not sure what you mean.  I'm a 
> real amateur at the Outlook object model.
> 
> Rocky
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve 
> Goodhall Sent: Thursday, September 09, 2010 8:55 AM To: Access 
> Developers discussion and problem solving Subject: Re: [AccessD] 
> Deleting Outlook Contacts
> 
>   BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }I
>   think
> your problem is with the way For Each iterates in olContacts.  I am 
> out on a customer site and don't have access to all my test beds, but 
> I would suggest that you index the contact to be deleted and count 
> down from the number of items in the olContacts collection.  I don't 
> remember whether that index is zero based or one based.
>  I also suggest that you lose the "GoTo" but that's just style.
>  Regards,
>  Steve Goodhall, MSCS, PMP
>  248-505-5204
>  On Thu 09/09/10 11:25 AM , "Rocky Smolin" rockysmolin at bchacc.com
> sent:
>  Dear List:
>  Still struggling with deleting the Outlook contacts.  I found that  
> looping through the items and deleting them deleted half so if I 
> started with 1000 contacts at the end of the loop I had 500 left.  If 
> I sent the program back through the loop I ended up with 250.  etc.
>  So iterating that loop until the Count = 0 works but it's kludgey.
> Why does
>  it leave half of the contacts behind each time?
>  Here's the code:
>      ' delete all the current contacts
>      Set olContacts = olFolder.Items
>  DeleteAgain:
>      Me.txtProcessing = "Deleting..." & olContacts.Count
>      Me.Repaint
>      For Each olContactItem In olContacts
>          'MsgBox olContactItem.LastName & ", " &
>          olContactItem.FirstName & "
>  - " & olContacts.Count
>          olContactItem.Delete
>          DoEvents
>      Next
>      Set olContacts = olFolder.Items
>      If olContacts.Count  0 Then GoTo DeleteAgain:
>  Me.txtProcessing displays the number of contacts each time through  
> the big loop.  So that's how I know it's only deleting 1/2 each time. 
> When I uncomment the MsgBox line inside the loop, it shows the count 
> going to zero each time the loop executes.  But after the loop 
> finishes, there's still 1/2 the contacts left.  refreshing the count 
> by Set olContacts = olFolder.Items gives the right count again.
>  Any idea what the heck is going on here?
>  MTIA
>  Rocky
>  --
>  AccessD mailing list
>  AccessD at databaseadvisors.com [1]
>  http://databaseadvisors.com/mailman/listinfo/accessd
>  Website: http://www.databaseadvisors.com
> 
> 
> Links:
> ------
> [1] mailto:AccessD at databaseadvisors.com
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list