OL2000: (IMO) You Cannot Programmatically Add an E-mail Address to a Distribution List (269861)
The information in this article applies to:
This article was previously published under Q269861 NOTE: These procedures only apply if you have installed Outlook with the Internet Mail Only option. To determine your installation type, click About Microsoft Outlook on the Help menu. If you have the Internet Mail Only option installed, you see "Internet Mail Only". For information about the differences between Microsoft Outlook and Microsoft Outlook Express e-mail clients, click the following article number to view the article in the Microsoft Knowledge Base: 257824 OL2000: Differences Between Outlook and Outlook Express SYMPTOMS
The AddMembers method of a Distribution List item does not work unless the e-mail address can be resolved to a Contact item.
WORKAROUND
To work around this behavior, create a Contact for each e-mail address before you add it to the Distribution List item.
The following Outlook Visual Basic for Applications (VBA) code example demonstrates how you can programmatically create a Contact item and add it to a new Distribution List item:
Sub CreateDistributionList()
Dim myOlApp As Application
Dim myNameSpace As NameSpace
Dim myContact As ContactItem
Dim myDistList As DistListItem
Dim myMailItem As MailItem
Dim myRecipients As Recipients
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'Create the new Contact
Set myContact = myOlApp.CreateItem(olContactItem)
myContact.FullName = "User Name"
myContact.Email1Address = "username@domain.com"
myContact.Save
myContact.Display
'Create the Distribution List item
Set myDistList = myOlApp.CreateItem(olDistributionListItem)
myDistList.DLName = "Test Distribution List"
'The MailItem is required to
'create the Recipients collection
Set myMailItem = myOlApp.CreateItem(olMailItem)
Set myRecipients = myMailItem.Recipients
'A Contact with the following e-mail address
'must exist for the AddMembers method to work
myRecipients.Add "username@domain.com"
myRecipients.ResolveAll
myDistList.AddMembers myRecipients
myDistList.Save
myDistList.Display
End Sub
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below
to view the article in the Microsoft Knowledge Base:
146636 OL2000: Questions About Custom Forms and Outlook Solutions
Modification Type: | Major | Last Reviewed: | 9/29/2003 |
---|
Keywords: | kbbug kbnofix KB269861 |
---|
|