Microsoft KB Archive/269861

= OL2000: (IMO) You Cannot Programmatically Add an E-mail Address to a Distribution List =

Article ID: 269861

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



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 &quot;Internet Mail Only&quot;.

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(&quot;Outlook.Application&quot;) Set myNameSpace = myOlApp.GetNamespace(&quot;MAPI&quot;)

'Create the new Contact Set myContact = myOlApp.CreateItem(olContactItem) myContact.FullName = &quot;User Name&quot; myContact.Email1Address = &quot;username@domain.com&quot; myContact.Save myContact.Display

'Create the Distribution List item Set myDistList = myOlApp.CreateItem(olDistributionListItem) myDistList.DLName = &quot;Test Distribution List&quot;

'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 &quot;username@domain.com&quot; myRecipients.ResolveAll myDistList.AddMembers myRecipients myDistList.Save myDistList.Display

End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Steps to Reproduce the Behavior
The following code example demonstrates how to reproduce this behavior. This code creates a new Distribution List item without recipients and does not return any errors:

Sub ReproduceDistributionListIssue

Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myDistList As DistListItem Dim myMailItem As MailItem Dim myRecipients As Recipients

Set myOlApp = CreateObject(&quot;Outlook.Application&quot;) Set myNameSpace = myOlApp.GetNamespace(&quot;MAPI&quot;)

'Create the Distribution List item Set myDistList = myOlApp.CreateItem(olDistributionListItem) myDistList.DLName = &quot;Test Distribution List (IMO)&quot;

'The MailItem is required to create the Recipients collection Set myMailItem = myOlApp.CreateItem(olMailItem) Set myRecipients = myMailItem.Recipients

'The next line works only if name matches an entry in the Contacts   folder myRecipients.Add &quot;username@domain.com&quot; myRecipients.ResolveAll myDistList.AddMembers myRecipients myDistList.Save myDistList.Display

End Sub

