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



The information in this article applies to:

  • Microsoft Outlook 2000

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
				

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: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

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

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

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

End Sub
				

REFERENCES

For 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:MajorLast Reviewed:9/29/2003
Keywords:kbbug kbnofix KB269861