Steve Goodhall
steve at goodhall.info
Fri Sep 10 09:11:15 CDT 2010
BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }I
agree. This is running code to empty the Drafts folder.
This one runs inside Outlook, but it should be pretty easy to change
it to delete Contacts and use an object reference to run it from
Access. I think all it will take is to replace "Application" with a
reference to an Outlook instance.
Sub killDrafts()
Dim oFold As outlook.MAPIFolder
Dim oNS As outlook.NameSpace
Set oNS = Application.GetNamespace("MAPI")
Set oFold = oNS.GetDefaultFolder(olFolderDrafts)
Dim oItem As outlook.MailItem
Dim lItems As Long
Dim lItem As Long
lItems = oFold.Items.Count
For lItem = lItems To 1 Step -1
Set oItem = oFold.Items(lItem)
oItem.Delete
DoEvents
Next
End Sub
Regards,
Steve Goodhall, MSCS, PMP
248-505-5204
On Fri 10/09/10 9:02 AM , "Heenan, Lambert"
Lambert.Heenan at chartisinsurance.com sent:
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 ' 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 [4]
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 [5]
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com [6]
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
Links:
------
[1] mailto:accessd-bounces at databaseadvisors.com
[2] mailto:accessd-bounces at databaseadvisors.com
[3] mailto:rockysmolin at bchacc.com
[4] mailto:AccessD at databaseadvisors.com
[5] mailto:AccessD at databaseadvisors.com
[6] mailto:AccessD at databaseadvisors.com