Deleting Contacts and Dist Lists in same folder 
Author Message
 Deleting Contacts and Dist Lists in same folder

How do I delete Contact Items and Distribution Lists from within the same MAPI
folderusing a Loop command.  My code below will only delete one or the other and
stays in and endless loop because either contacts or distribution lists still
remain (depending on which code I use)...  see code below

FOR CONTACTS:
    Dim conOutLook As Outlook.ContactItem
        Set conOutLook = MAPIFolder5.Items.GetFirst

        Do Until conOutLook Is Nothing
           conOutLook.Delete
            Set conOutLook = MAPIFolder5.Items.GetNext
            Set conOutLook = MAPIFolder5.Items.GetFirst
        Loop

FOR DISTRIBUTION LISTS:
    Dim distOutlook As Outlook.DistListItem
        Set conOutLook = MAPIFolder5.Items.GetFirst

        Do Until conOutLook Is Nothing
           conOutLook.Delete
            Set conOutLook = MAPIFolder5.Items.GetNext
            Set conOutLook = MAPIFolder5.Items.GetFirst
        Loop

Your help would be appreciated.

Thanks

Todd



Fri, 24 Oct 2003 09:36:53 GMT  
 Deleting Contacts and Dist Lists in same folder
Dim your variable as an Object rather than a specific Outlook item type and
use a count down loop.

example.

Dim myObject As Object
Dim colItems As Outlook.Items
Dim lngCount as Long
Dim lngLoopCounter As Long

Set colItems =
Application.Getnamespace("MAPI").GetDefaultFolder(olFolderContacts).Items

lngCount = colItems.Count

For lngLoopCounter = lngCount To 1 Step -1
    Set myObject = colItems.Item(lngLoopCounter)
    If myObject Is Nothing Then
      '
    Else
      myObject.Delete
    End If

Next lngLoopCounter

Set myObject = Nothing
Set colItems = Nothing

--
/Neo


How do I delete Contact Items and Distribution Lists from within the same
MAPI
folderusing a Loop command.  My code below will only delete one or the other
and
stays in and endless loop because either contacts or distribution lists
still
remain (depending on which code I use)...  see code below

FOR CONTACTS:
    Dim conOutLook As Outlook.ContactItem
        Set conOutLook = MAPIFolder5.Items.GetFirst

        Do Until conOutLook Is Nothing
           conOutLook.Delete
            Set conOutLook = MAPIFolder5.Items.GetNext
            Set conOutLook = MAPIFolder5.Items.GetFirst
        Loop

FOR DISTRIBUTION LISTS:
    Dim distOutlook As Outlook.DistListItem
        Set conOutLook = MAPIFolder5.Items.GetFirst

        Do Until conOutLook Is Nothing
           conOutLook.Delete
            Set conOutLook = MAPIFolder5.Items.GetNext
            Set conOutLook = MAPIFolder5.Items.GetFirst
        Loop

Your help would be appreciated.

Thanks

Todd



Fri, 24 Oct 2003 09:57:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Delete Contacts from "Contact " Folder Automatically

2. NEWBIE: to delete distrbution list from contact list

3. Adding/Deleting Contacts in Public Folders

4. problem when deleting contact folder with VB

5. How make list of the other folder contact ?

6. Members property of contact folder distribution lists - returns gobbledygook in lovely looking array

7. Getting Contact list from another FOLDER

8. Distribution lists in the Contacts Folder

9. Using VBA to Create a Contact Folder Distribution List from MS Access

10. Set Contact Folder to be E-Mail Address List in Code

11. Get list of all Contact folder names

12. Public Folder Contact List

 

 
Powered by phpBB® Forum Software