A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Adding a Contact with multiple e-mail addresses to a Distribution



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 21st 09, 12:27 AM posted to microsoft.public.outlook.program_vba
David Lingren
external usenet poster
 
Posts: 6
Default Adding a Contact with multiple e-mail addresses to a Distribution


We are trying to build an Outlook Contacts folder from an Access database.
There are several Distribution Lists we want to add to the folder.

How can I programatically create a distribution list entry for an Outlook
Contact that has multiple e-mail addresses?

In the example below (running in Microsoft Access) "John Smith" has one
e-mail address in his Contact item and Jim Jones has two e-mail addresses in
his Contact item.

The first CreateRecipient works fine. John Smith appears in the distribution
list, his display name is "John Smith )" and the icon to the
left of his name is the Outlook Contact busines card icon. If you
double-click on the entry the Contact form comes up.

The second CreateRecipient fails. The Resolve function returns false and
nothing is added to the list.

The third CreateRecipient succeeds, but the Display Name is "Jim Jones" and
the icon to the left of the name is the notecard that indicates a non-Contact
entry. This entry looks like it is NOT associated with an Outlook Contact.

However - if you double-click on the entry the Contact form comes up, so the
association gets made somehow. It's just that the icon and name are different.

Note that if you use the "Select Members" dialog the icon and name are set
correctly, but you can't do it from VBA. It seems a small difference, but we
want the lists to "look right".

Any ideas?

PS

Many bonus points awarded if you can tell me how to change the user profile
used in the session. The Logon and Logoff methods don't seem to work at all.
We have to manually start Outlook with the correct profile before we run the
program.




Sub AddNewMember()
'Adds a member to a new distribution list
Dim ol As New Outlook.Application
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim oDistListItem As Outlook.DistListItem
Dim oRecipient As Outlook.Recipient

On Error Resume Next
' ol.Session.Logoff
' ol.Session.Logon "ETaiko", , True, True

Set oStore = ol.Session.Stores("ETaiko Folders")
Set oRoot = oStore.GetRootFolder
Set oFolder = oRoot.folders("Contacts")

Set oDistListItem = oFolder.Items.Add(olDistributionListItem)
oDistListItem.DLName = "AAA Test DGroup"

'Create recipients for distlist
Set oRecipient = ol.Session.CreateRecipient("John Smith")
oRecipient.Resolve
Debug.Print "1 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
oDistListItem.Close (olSave)

Set oRecipient = ol.Session.CreateRecipient("Jim Jones")
Debug.Print "2 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
Debug.Print Err.Number & " " & Err.Description
oDistListItem.Close (olSave)

Set oRecipient = ol.Session.CreateRecipient("Jim Jones )")
Debug.Print "3 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
Debug.Print Err.Number & " " & Err.Description
oDistListItem.Close (olSave)

End Sub

  #2  
Old February 21st 09, 02:19 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Adding a Contact with multiple e-mail addresses to a Distribution

Pass an e-mail to CreateRecipient address rather than a name.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
...

We are trying to build an Outlook Contacts folder from an Access database.
There are several Distribution Lists we want to add to the folder.

How can I programatically create a distribution list entry for an Outlook
Contact that has multiple e-mail addresses?

In the example below (running in Microsoft Access) "John Smith" has one
e-mail address in his Contact item and Jim Jones has two e-mail addresses
in
his Contact item.

The first CreateRecipient works fine. John Smith appears in the
distribution
list, his display name is "John Smith )" and the icon to
the
left of his name is the Outlook Contact busines card icon. If you
double-click on the entry the Contact form comes up.

The second CreateRecipient fails. The Resolve function returns false and
nothing is added to the list.

The third CreateRecipient succeeds, but the Display Name is "Jim Jones"
and
the icon to the left of the name is the notecard that indicates a
non-Contact
entry. This entry looks like it is NOT associated with an Outlook Contact.

However - if you double-click on the entry the Contact form comes up, so
the
association gets made somehow. It's just that the icon and name are
different.

Note that if you use the "Select Members" dialog the icon and name are set
correctly, but you can't do it from VBA. It seems a small difference, but
we
want the lists to "look right".

Any ideas?

PS

Many bonus points awarded if you can tell me how to change the user
profile
used in the session. The Logon and Logoff methods don't seem to work at
all.
We have to manually start Outlook with the correct profile before we run
the
program.




Sub AddNewMember()
'Adds a member to a new distribution list
Dim ol As New Outlook.Application
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim oDistListItem As Outlook.DistListItem
Dim oRecipient As Outlook.Recipient

On Error Resume Next
' ol.Session.Logoff
' ol.Session.Logon "ETaiko", , True, True

Set oStore = ol.Session.Stores("ETaiko Folders")
Set oRoot = oStore.GetRootFolder
Set oFolder = oRoot.folders("Contacts")

Set oDistListItem = oFolder.Items.Add(olDistributionListItem)
oDistListItem.DLName = "AAA Test DGroup"

'Create recipients for distlist
Set oRecipient = ol.Session.CreateRecipient("John Smith")
oRecipient.Resolve
Debug.Print "1 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
oDistListItem.Close (olSave)

Set oRecipient = ol.Session.CreateRecipient("Jim Jones")
Debug.Print "2 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
Debug.Print Err.Number & " " & Err.Description
oDistListItem.Close (olSave)

Set oRecipient = ol.Session.CreateRecipient("Jim Jones
)")
Debug.Print "3 " & oRecipient.Resolve
oDistListItem.AddMember oRecipient
Debug.Print Err.Number & " " & Err.Description
oDistListItem.Close (olSave)

End Sub



  #3  
Old February 24th 09, 05:35 AM posted to microsoft.public.outlook.program_vba
David Lingren
external usenet poster
 
Posts: 6
Default Adding a Contact with multiple e-mail addresses to a Distribut

Thanks for your quick reaponse, but passing the e-mail address to
CreateRecipient doesn't work, either. The icon displayed is the non-contact
"notecard" and the Display Name contains the e-mail address, not the contact
name.

"Dmitry Streblechenko" wrote:

Pass an e-mail to CreateRecipient address rather than a name.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-


  #4  
Old February 24th 09, 03:07 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Adding a Contact with multiple e-mail addresses to a Distribut

I can only recomment Redemption which allows to prograammatically add a
contact through the RDODistListItem.AddContact method:
http://www.dimastr.com/redemption/rd...stListItem.htm

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
news
Thanks for your quick reaponse, but passing the e-mail address to
CreateRecipient doesn't work, either. The icon displayed is the
non-contact
"notecard" and the Display Name contains the e-mail address, not the
contact
name.

"Dmitry Streblechenko" wrote:

Pass an e-mail to CreateRecipient address rather than a name.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-




  #5  
Old February 28th 09, 05:24 AM posted to microsoft.public.outlook.program_vba
David Lingren
external usenet poster
 
Posts: 6
Default Adding a Contact with multiple e-mail addresses to a Distribut

Dmitry,

Thanks for your suggestion of 2/24. I downloaded and installed Outlook
Redemption and have made considerable progress. However, I have a related
problem.

I am trying to extract Contacts and Personal Distribution Lists to an Access
database so we can analyse them. I can't find a way to tell which members of
a MAPIPDL are related to Contacts in the address book so I can retrieve the
"FileAs" property that uniquely identifies each of them.

The code below is as close as I can get. The problem is that the
"oMember.GetContact" method always returns Nothing for members of a MAPIPDL.
Is there another way I can get from a MAPIPDL member to the related Contact?

Outlook (2007) does this somehow...

Thanks for all your help so far. By the way, OutlookSpy is terrific!

David Lingren


Sub EnumerateRDOAddressLists()

' Set up Redemption Objects.
Dim oSession As Redemption.RDOSession
Dim oAddressBook As Redemption.RDOAddressBook
Dim oAddressLists As Redemption.RDOAddressLists
Dim oAddresslist As Redemption.RDOAddressList
Dim oAddressEntries As Redemption.RDOAddressEntries
Dim oAddressEntry As Redemption.RDOAddressEntry
Dim oContact As Redemption.RDOContactItem
Dim oMembers As Redemption.RDOAddressEntries
Dim oMember As Redemption.RDOAddressEntry

Set oSession = New RDOSession
oSession.Logon ("ETaiko")

Set oAddressBook = oSession.AddressBook
Set oAddressLists = oAddressBook.AddressLists

For Each oAddresslist In oAddressLists
Debug.Print oAddresslist.Name

Set oAddressEntries = oAddresslist.AddressEntries
For Each oAddressEntry In oAddressEntries
Debug.Print oAddressEntry.Type & " " & oAddressEntry.Address & "
" & oAddressEntry.Name

If oAddressEntry.Type = "MAPIPDL" Then
Set oContact = oAddressEntry.GetContact
Set oMembers = oAddressEntry.Members
Debug.Print "MAPIPDL " & oContact.FileAs & " " &
oMembers.Count

For Each oMember In oMembers
Debug.Print "Member " & oMember.Name & ", " &
oMember.Address & ", " & oMember.Type
Set oContact = oMember.GetContact
If Not (oContact Is Nothing) Then
Debug.Print "Member FileAs " & oContact.FileAs
End If
Next
Else
Set oContact = oAddressEntry.GetContact
If Not (oContact Is Nothing) Then Debug.Print "CONTACT " &
oContact.FileAs
End If
Next
Next

Set oMember = Nothing
Set oMembers = Nothing
Set oContact = Nothing
Set oAddressEntry = Nothing
Set oAddressEntries = Nothing
Set oAddresslist = Nothing
Set oAddressLists = Nothing
oSession.Logoff
Set oSession = Nothing
End Sub



"Dmitry Streblechenko" wrote:

I can only recomment Redemption which allows to prograammatically add a
contact through the RDODistListItem.AddContact method:
http://www.dimastr.com/redemption/rd...stListItem.htm

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
news
Thanks for your quick reaponse, but passing the e-mail address to
CreateRecipient doesn't work, either. The icon displayed is the
non-contact
"notecard" and the Display Name contains the e-mail address, not the
contact
name.

"Dmitry Streblechenko" wrote:

Pass an e-mail to CreateRecipient address rather than a name.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-





  #6  
Old March 2nd 09, 05:36 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Adding a Contact with multiple e-mail addresses to a Distribut

I hads no problem with the following script (assumign you have a contact
named "Dmitry Streblechenko").

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Contacts = Session.GetDefaultFolder(olFolderContacts)
set DL = Contacts.Items.Add("IPM.DistList")
DL.DLName = "test contact"
set Contact = Contacts.Items("Dmitry Streblechenko") 'add email1 address to
the DL
DL.AddContact Contact, 0
DL.Save

set AE = DL.Members(1)
set Contact = AE.GetContact
MsgBox Contact.FileAs

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
...
Dmitry,

Thanks for your suggestion of 2/24. I downloaded and installed Outlook
Redemption and have made considerable progress. However, I have a related
problem.

I am trying to extract Contacts and Personal Distribution Lists to an
Access
database so we can analyse them. I can't find a way to tell which members
of
a MAPIPDL are related to Contacts in the address book so I can retrieve
the
"FileAs" property that uniquely identifies each of them.

The code below is as close as I can get. The problem is that the
"oMember.GetContact" method always returns Nothing for members of a
MAPIPDL.
Is there another way I can get from a MAPIPDL member to the related
Contact?

Outlook (2007) does this somehow...

Thanks for all your help so far. By the way, OutlookSpy is terrific!

David Lingren


Sub EnumerateRDOAddressLists()

' Set up Redemption Objects.
Dim oSession As Redemption.RDOSession
Dim oAddressBook As Redemption.RDOAddressBook
Dim oAddressLists As Redemption.RDOAddressLists
Dim oAddresslist As Redemption.RDOAddressList
Dim oAddressEntries As Redemption.RDOAddressEntries
Dim oAddressEntry As Redemption.RDOAddressEntry
Dim oContact As Redemption.RDOContactItem
Dim oMembers As Redemption.RDOAddressEntries
Dim oMember As Redemption.RDOAddressEntry

Set oSession = New RDOSession
oSession.Logon ("ETaiko")

Set oAddressBook = oSession.AddressBook
Set oAddressLists = oAddressBook.AddressLists

For Each oAddresslist In oAddressLists
Debug.Print oAddresslist.Name

Set oAddressEntries = oAddresslist.AddressEntries
For Each oAddressEntry In oAddressEntries
Debug.Print oAddressEntry.Type & " " & oAddressEntry.Address &
"
" & oAddressEntry.Name

If oAddressEntry.Type = "MAPIPDL" Then
Set oContact = oAddressEntry.GetContact
Set oMembers = oAddressEntry.Members
Debug.Print "MAPIPDL " & oContact.FileAs & " " &
oMembers.Count

For Each oMember In oMembers
Debug.Print "Member " & oMember.Name & ", " &
oMember.Address & ", " & oMember.Type
Set oContact = oMember.GetContact
If Not (oContact Is Nothing) Then
Debug.Print "Member FileAs " & oContact.FileAs
End If
Next
Else
Set oContact = oAddressEntry.GetContact
If Not (oContact Is Nothing) Then Debug.Print "CONTACT " &
oContact.FileAs
End If
Next
Next

Set oMember = Nothing
Set oMembers = Nothing
Set oContact = Nothing
Set oAddressEntry = Nothing
Set oAddressEntries = Nothing
Set oAddresslist = Nothing
Set oAddressLists = Nothing
oSession.Logoff
Set oSession = Nothing
End Sub



"Dmitry Streblechenko" wrote:

I can only recomment Redemption which allows to prograammatically add a
contact through the RDODistListItem.AddContact method:
http://www.dimastr.com/redemption/rd...stListItem.htm

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"David Lingren" wrote in message
news
Thanks for your quick reaponse, but passing the e-mail address to
CreateRecipient doesn't work, either. The icon displayed is the
non-contact
"notecard" and the Display Name contains the e-mail address, not the
contact
name.

"Dmitry Streblechenko" wrote:

Pass an e-mail to CreateRecipient address rather than a name.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-






 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple e-mail addresses merged into distribution list red14red Outlook - Using Contacts 2 October 1st 08 08:17 PM
Adding Distribution list to an e-mail with multiple mailboxes Jamie Outlook and VBA 1 May 20th 07 10:13 PM
Adding email addresses to an old distribution list cjm563 Outlook - Using Contacts 5 January 12th 07 08:35 PM
Adding a contact to one or multiple distribution lists Andy E Outlook - Using Contacts 4 December 28th 06 07:21 PM
Displaying multiple e-mail addresses for one contact Tony Reynolds Outlook - Using Contacts 1 February 16th 06 05:15 PM


All times are GMT +1. The time now is 05:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.