Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with creating distribution list in outlook

Status
Not open for further replies.

axism

MIS
May 17, 2005
58
Hi, I need help with deleting all my contacts in my outlook except for the 2 distribution list i made. Is there a way to do it? thank you
 
Are you talking programatically though code, or simply openeing outlook and hitting the delete key?!

------------------------
Hit any User to continue
 
Good good.. in that case yes; the following code will delete all of your contacts. You just need an if statement within the 'for each' look to stop it deleting your distribution lists.

Code:
Sub DeleteContact()

'Ensure reference to the outlook object is made.

    Dim olSession As Outlook.Application
    Dim olNamespace As NameSpace
    Dim olContacts As Outlook.MAPIFolder
    Dim olItem As ContactItem
    
    Set olSession = New Outlook.Application
    Set olNamespace = olSession.GetNamespace("MAPI")
    Set olContacts = olNamespace.GetDefaultFolder(olFolderContacts)

    For Each olItem In olContacts.Items
        olItem.Delete
    Next
    
    Set olSession = Nothing
    Set olNamespace = Nothing
    Set olContacts = Nothing
    
End Sub

A GREAT resource for outlook coding in ms access can be found at:
:)

------------------------
Hit any User to continue
 
i was deleting the whole folder instead of going thro each item before. was thinking there might be an object type for distribution list so i can just copy all the distributions to a temp array or place holder and put them back after deletion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top