views:

71

answers:

2

How can I ensure the contacts I add to an Outlook distribution list are displayed with both name and email address? These contacts may not exist in any other address book, just the distribution list. Currently they show up just as an email address (in both columns).

alt text

Here's roughly the VBA we're using:

    Do Until RS.EOF

        //here's where we want to inject RS!FirstName, RS!Surname etc
        objRecipients.Add RS!Email
        objRecipients.Resolve

        RS.MoveNext
    Loop


    Set objDistList = contactsFolder.Items.Add("IPM.DistList")
    objDistList.DLName = "Whatever"

    objDistList.AddMembers objRecipients
    objDistList.Save

    etc
A: 

I think you have to create a ContactItem for each recipient so you can define the name. Here's an example:

Sub testdistlist()

    Dim oRecips As Recipients
    Dim ciDist As DistListItem
    Dim ci As ContactItem
    Dim mi As MailItem

    Set mi = Application.CreateItem(olMailItem)
    Set oRecips = mi.Recipients

    Set ciDist = Application.CreateItem(olDistributionListItem)

    'replace this with your recordset loop
    Set ci = Application.CreateItem(olContactItem)
    ci.FirstName = "John"
    ci.LastName = "Lennon"
    ci.Email1Address = "[email protected]"
    ci.Save

    oRecips.Add ci.FullName

    Set ci = Application.CreateItem(olContactItem)
    ci.FirstName = "Ringo"
    ci.LastName = "Starr"
    ci.Email1Address = "[email protected]"
    ci.Save

    oRecips.Add ci.FullName
    'end replace

    ciDist.AddMembers oRecips

    ciDist.Save
    ciDist.Display
    mi.Close olDiscard

End Sub
Dick Kusleika
A: 

Thanks to Dick Kusleika for his answer but Graeme's answer here gave me an idea there could be an easier way.

And that is just to use angle brackets in the entry to the distribution list. As in "Ringo Starr<[email protected]>"

Which works just fine.

So my original example would look like this:

objRecipients.Add RS!FullName & "<" & RS!Email & ">"
hawbsl