Avoid a Distribution List when looping through Items ?

G

Gordon

Hi;

Just where do you place you test statement i.e. myObj.Class =
olDistributionClass,
when coding to loop through the contacts.item collection ?

Like this:

For Each contact In objAllContacts
' test for type of object
If contact.Class = olDistributionList Then
Debug.Print "I've got one"
End If


Debug.Print contact.FileAs & " " & contact.Email1Address

Next

My loop keeps crashing when I hit the DL.

This makes since but how do avoid this ? Test for this type of contact.
But where ?

Is it just me or is the Outlook Object Model hard to learn ?
-

Thanks for your responses,

Gordon
 
S

Sue Mosher [MVP-Outlook]

You left out a critical statement -- how you are declaring the variable named contact. You need to declare it as Object, not ContactItem.

Then, your test needs to be an If ... Else ... End If block not an If .... End If block. The way you have it now, you're still trying to access the FileAs and Email1Address properties even if it's a DL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top