Programmatically Create an Outlook Distribution List

I want to populate an Outlook Contacts folder with data from a SQL database, and need to automatically assign contacts to a variety of distribution lists. Does anyone have any code for programatically creating distribution lists and adding contacts to them?

I am running Exchange 2003 and Outlook 2003.
purplesoupProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Naser GabajE&P Senior Software SpecialistCommented:
Greetings purplesoup,

Check this:

http://www.cdolive.com/dlscript.htm

Good Luck!
Naser
David LeeCommented:
Hi purplesoup,

Here are two previous questions where I show how to make a dist list via code.  Neither are specifically for SQL, but either one could be modified to use it.

http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21931903.html
http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21509190.html

Cheers!
purplesoupProgrammerAuthor Commented:
Is there a way to actually add contacts rather than email addresses to a distribution list?

If I go to the contact folder and manually right click and say "new distribution list" it will add contacts to the distribution list - clicking on entries on the left hand list will open the contact. Whereas using these macros it only adds the email address.

If you look at one of these contact distribution lists in the VBA "Watch" window each member appears as a lot of weird characters - squares and question marks, as each member entry is of type string but it appears to actually have a contact object squashed in there.
David LeeCommented:
> Is there a way to actually add contacts rather than email addresses to a distribution list?
You add the name or email address of the contact.  You cannot add a contact item itself directly to the list.  When Outlook resolves the entries in the dist list it finds the contacts.

> If I go to the contact folder and manually right click and say "new distribution list" it will add contacts to the distribution list - clicking on entries on the left hand list will open the contact.
I'm not a member of either the Outlook development team nor a Microsoft employee so I can't say for certain, but I expect that in the background the code is doing exactly the same thing.  You're simply seeing the difference between something done visually and the same action performed in code.  In the GUI you select a name and Outlook adds that contact's email address to the dist list.  You can do the same thing in code.  If I have opened a certain contact item in code, then I can add that contact's name/email address to the dist list.  

> but it appears to actually have a contact object squashed in there.
It may seem so, but it doesn't actually embed the contact item.  Dist lists are made up of Recipient objects, not ContactItems.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.