add to existing distribution list

B

barret bonden

Trying to add to an existing distribution list; (from MS Access to Outlook
2003) ; code below can add, but always creates new DL (see below); skipping
through Access records into general top level contacts was easy, DL work has
been very frustrating.
Code below works (it adds to a list) but it needs to refer to a known list.
How do I do this successfully ?
I've played with :
objDistList =
myFolder.Items.Add(Outlook.OlItemType.olDistributionListItem)
in other code but get "object variable not set" even though I can see it has
been !



Dim objOutlook As New Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objDistList As Outlook.DistListItem
Dim objMail As Outlook.MailItem
Dim objRecipients As Outlook.Recipients


Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objDistList = objOutlook.CreateItem(olDistributionListItem)
Set objMail = objOutlook.CreateItem(olMailItem)
Set objRecipients = objMail.Recipients
objDistList.DLName = InputBox("Enter name of Distribution List")
'objDistList.DLName = "test"



'For i = 1 To Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
'objRecipients.Add (Range("C" & i).Value)
'Next i


objRecipients.Add "(e-mail address removed)"
objRecipients.Add "(e-mail address removed)"


objDistList.AddMembers objRecipients
'objDistList.Display
objDistList.Save
objRecipients.ResolveAll

Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objDistList = Nothing
Set objMail = Nothing
Set objRecipients = Nothing
 
S

Sue Mosher [MVP]

You need to use the MAPIFolder.Items.Find method to return the existing list
based on a query against some known criteria, such as the Subject (i.e. list
name).
 
B

barret bonden

Ahhhh ! (sigh of relief) the guardian angel of Outlook programmers is
still there. Ms. Mosher, I've been professionally programming in VB/VBA for
16 + (?) years now , but still can't make substantial heads or tails of
Outlook syntax; I have no real capacity to be creative here.

This is crass of me, but could you be more explicit ? Or direct me to some
code (been looking for weeks) that solves this ?
 
S

Sue Mosher [MVP]

There's nothing special about Outlook syntax. It's all objects, properties,
methods, and events, the same as with other libraries you may have used in
VB/VBA. The method you need, Items.Find, is well documented in Outlook VBA
Help and in the Outlook Developer Reference on MSDN.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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