A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

code to delete all contacts



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 15th 08, 05:35 AM posted to microsoft.public.outlook
[email protected]
external usenet poster
 
Posts: 1
Default code to delete all contacts

Using what I have learned from this group and Sue Mosher's site, I
pieced together code to delete all contacts in a contact folder from
Outlook 2002 on Microsoft Exchange server. The code works good except
it will only delete about half the contacts. I run it again and it
deletes more contacts, and on and on until all the contacts have been
deleted. I want the code to keep running until the contact folder is
empty. Can anyone help me see what I have done wrong? I thank you in
advance. The code follows:

Sub DeleteContact()


Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
'Set myOlApp = CreateObject("Outlook.Application")
Set myOlApp = Outlook.Application

Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts =
myNamespace.GetDefaultFolder(olFolderContacts).Ite ms
''Set myItems = myContacts.Restrict("[LastModificationTime]
'01/1/2003'")
Set myItems = myContacts

'Prompt the user for confirmation

strPrompt = "Are you sure you want to delete all the contacts in
the contact folder?"

If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
MsgBox "This may take several minutes. Click OK to begin.",
vbOKOnly

For Each myItem In myItems

If (myItem.Class = olContact) Then
'Debug.Print myItem.Class & "myitem.class"
myItem.Delete
End If
Next
MsgBox ("All contacts have been deleted!")
End If

End Sub

~Thank you, ~BJM
Ads
  #2  
Old January 15th 08, 07:53 AM posted to microsoft.public.outlook
Milly Staples [MVP - Outlook][_2_]
external usenet poster
 
Posts: 2,202
Default code to delete all contacts

microsoft.public.outlook_vba is where this belongs.

--
Milly Staples [MVP - Outlook]

Post all replies to the group to keep the discussion intact. All
unsolicited mail sent to my personal account will be deleted without
reading.

After furious head scratching, asked:

| Using what I have learned from this group and Sue Mosher's site, I
| pieced together code to delete all contacts in a contact folder from
| Outlook 2002 on Microsoft Exchange server. The code works good except
| it will only delete about half the contacts. I run it again and it
| deletes more contacts, and on and on until all the contacts have been
| deleted. I want the code to keep running until the contact folder is
| empty. Can anyone help me see what I have done wrong? I thank you in
| advance. The code follows:
|
| Sub DeleteContact()
|
|
| Dim myOlApp As Outlook.Application
| Dim myNamespace As Outlook.NameSpace
| Dim myContacts As Outlook.Items
| Dim myItems As Outlook.Items
| Dim myItem As Object
| 'Set myOlApp = CreateObject("Outlook.Application")
| Set myOlApp = Outlook.Application
|
| Set myNamespace = myOlApp.GetNamespace("MAPI")
| Set myContacts =
| myNamespace.GetDefaultFolder(olFolderContacts).Ite ms
| ''Set myItems = myContacts.Restrict("[LastModificationTime]
| '01/1/2003'")
| Set myItems = myContacts
|
| 'Prompt the user for confirmation
|
| strPrompt = "Are you sure you want to delete all the contacts in
| the contact folder?"
|
| If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
| MsgBox "This may take several minutes. Click OK to begin.",
| vbOKOnly
|
| For Each myItem In myItems
|
| If (myItem.Class = olContact) Then
| 'Debug.Print myItem.Class & "myitem.class"
| myItem.Delete
| End If
| Next
| MsgBox ("All contacts have been deleted!")
| End If
|
| End Sub
|
| ~Thank you, ~BJM
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My zip code is in the wrong position in contacts Arlene Outlook - Using Contacts 4 March 28th 07 01:19 AM
How to delete multiple contacts through c# code pramod Add-ins for Outlook 1 December 27th 06 06:22 PM
Exporting Contacts Code [email protected] Outlook - Using Contacts 1 June 29th 06 07:10 PM
Telephone country code in Contacts JW Outlook - Using Contacts 1 March 15th 06 10:56 PM
I get an error code and can't get to my contacts list John Outlook - Using Contacts 0 February 18th 06 10:41 PM


All times are GMT +1. The time now is 06:26 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.