[AccessD] Deleting Outlook Contacts

Heenan, Lambert Lambert.Heenan at chartisinsurance.com
Fri Sep 10 08:02:25 CDT 2010


Close Charlotte, but no prize :-)

The collection has a Count property, so  just use it in a for loop that runs backwards..

Dim n as Long

    ' delete all the current contacts
    Set olContacts = olFolder.Items
    
    Me.Repaint
    For N = olContacts.Count- 1 to 0 Step -1 ' <- Seems many people forget the optional Step clause of a FOR statement
	   Me.txtProcessing = "Deleting..." & olContacts.Count
        olContacts(n).Delete
        DoEvents
    Next

Lambert

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


_______________________________________________________________________________________

Note: This e-mail is subject to the disclaimer contained at the bottom of this message.
_______________________________________________________________________________________




In short, when you delete the contact, the next record becomes the current one.  That one is skipped as you do a "move next" to get to the next record, effectively skipping the 'new' current record.  This is why only half are removed.  Or at least that is my understanding of it.  You certainly see that sort of behaviour in Excel when using that sort of method to delete records.

regards
Darryl. 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust
Sent: Friday, 10 September 2010 11:39 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Deleting Outlook Contacts

Rocky,

To get deletes to work properly, you have to move backwards through
the recordset.   Instead of using For Each, try moving to the last
record first and do until EOF and BOF.

Charlotte Foust

On Thu, Sep 9, 2010 at 8:25 AM, Rocky Smolin <rockysmolin at bchacc.com> wrote:
> 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
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com _______________________________________________________________________________________

The information transmitted in this message and its attachments (if any) is intended only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information, by persons or entities other than the intended recipient is prohibited.

If you have received this in error, please contact the sender and delete this e-mail and associated material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or distribute the information contained in this e-mail and any attached files, with the permission of the sender.

This message has been scanned for viruses.
_______________________________________________________________________________________

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