GetOneNameViaCDO question

F

Florian Rosch

Hi,
I'm using the code below from Siegfried Weber in a few of my custom created
forms with OL 2000 (on EXC2000). It works perfectly when I need just one
name in the field, but now I need this code modified so that I can choose
more than one recipient. But as I'm not the programming crack, I don't know
how to change the code so that I can choose an undefined number of names
from the GAL.

Can someone help me please?

Thank you!
Florian




-----------------snip---------------------
Function GetOneNameViaCDO()
Const cdoE_USER_CANCEL = &H80040113
' start CDO session
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False
On Error Resume Next
Set colCDORecips = objSession.AddressBook(, "Pick a Name", , , 1, "My
Choice")
If Err = 0 Then
If colCDORecips.Count <> 1 Then
MsgBox "Please choose exactly one name!.", , "Choose One Name"
Else
strName = colCDORecips.Item(1).AddressEntry.Name
If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot return a name, because you clicked No on the
e-mail address access dialog. You need to try again and click Yes this
time.", ,"E-mail Address Access"
End If
End If
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If
GetOneNameViaCDO = strName
' release objects
objSession.Logoff
Set colCDORecips = Nothing
Set objSession = Nothing
End Function

Sub CommandButton1_Click()
Item.Userproperties("customNamefield") = GetOneNameViaCDO
End Sub
 
F

Florian Rosch

Hi,
it's me again. I found the solution to add more than one recipient on
www.slipstick.com:
http://www.slipstick.com/dev/code/selectnames.htm#addresses
(btw: thanks to Sue for such a valuable and helpful resource!!!)

It works fine so far, the address book dialog pops up and I can choose a lot
of names from the GAL. But one question is still there: How do I add these
names from the GAL to a self defined text field?


Thanks!
Florian


The nonworking code I use is:


---------snip-----------------------
Sub CommandButton1_Click()
AddRecipsViaCDO(Item.Userproperties("Meetingattendees"))
End Sub


Sub AddRecipsViaCDO(objMail)
Const cdoE_USER_CANCEL = &H80040113
' start CDO session
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False
On Error Resume Next
' show address book
Set colCDORecips = objSession.AddressBook(, "Pick Names", , , 1,
"Recipients")
If Err = 0 Then
' put CDO recipients into Outlook message
Set colRecips = objMail.Recipients
For Each objCDORecip In colCDORecips
Set objRecip = colRecips.Add(objCDORecip.AddressEntry.Address)
If Err = 287 Then
' security block triggered
MsgBox "Outlook cannot add recipients, because you clicked No on the
e-mail address access dialog. You need to try again and click Yes this
time.", , "E-mail Address Access"
Exit For
End If
Next
colRecips.ResolveAll
ElseIf Err = cdoE_USER_CANCEL Then
' user canceled the address book dialog -
' do nothing or provide a message to user
End If
' release objects
objSession.Logoff
Set colCDORecips = Nothing
Set objRecip = Nothing
Set objCDORecip = Nothing
Set colRecips = Nothing
Set objSession = Nothing
End Sub
 
S

Sue Mosher [MVP]

The colCDORecips object returned by the Session.AddressBook method in the AddRecipsViaCDO subroutine is a collection of the recipients you selected. You can loop through that collection to build a string from the recipient names and set your property value to the result:

For Each objRecip in colCDORecips
strAddList = strAddList & ";" & objRecip.Name
Next
Item.Userproperties("customNamefield") = Mid(strAddList, 2)

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm
 
F

Florian Rosch

That's great, it works now. Thank you very much!

Is there a way to change this code somehow, that the upcoming address book
is automatically the Outlook contacts folder instead of the Global Address
List?

It's not that important, but it would be nice ;-)

Thanks!
Florian



The colCDORecips object returned by the Session.AddressBook method in the
AddRecipsViaCDO subroutine is a collection of the recipients you selected.
You can loop through that collection to build a string from the recipient
names and set your property value to the result:

For Each objRecip in colCDORecips
strAddList = strAddList & ";" & objRecip.Name
Next
Item.Userproperties("customNamefield") = Mid(strAddList, 2)

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top