Getting outlook contacts into a combo box

W

Wayne Levin

Hi

1> I am trying to populate a combo box on my form with 'contact names'
from the default contact folder in outlook 2003.

2> Also the 'contact name' would then be saved into the recordset while a
button to send that contact an email would
get the selected 'contact name's email address .....?
- should the combo box be 'bound' so as to save the selection
(ie contacts name) ?

(I am familiar with sending an email from access - just need to get the
email address after selection.)

Thanks in advance
Wayne
 
M

Marc

Wayne Levin said:
Hi

1> I am trying to populate a combo box on my form with 'contact names'
from the default contact folder in outlook 2003.

2> Also the 'contact name' would then be saved into the recordset while a
button to send that contact an email would
get the selected 'contact name's email address .....?
- should the combo box be 'bound' so as to save the selection
(ie contacts name) ?

(I am familiar with sending an email from access - just need to get the
email address after selection.)

Thanks in advance
Wayne
hi
http://msdn.microsoft.com/library/d.../html/deovrworkingwithoutlookfoldersitems.asp

is an OfficeXP version of navigating the outlook contact folder.

HTH
Marc
 
M

Marc

Wayne Levin said:
Thanks Marc

Understand the object model.
Code to populate combo ??
Ok, if you take the routine there GetItemFromName.
Remove the restrict coding if you want to get each contact.
In the area where it is navigating through each matching entry, ie the
display, change this to add it to the comobox.
Remove the exit functions that are now in the wrong place.

Adding to a combox :
Concatenate into a string each value delimited by a semicolon. Be careful to
concatenate in the same order.
HTH
Marc
 
W

Wayne Levin

Here is my code which produces the list of contacts.

Public Function ReadContacts()

Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim CurrentItem
Dim strOutput

Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFoldercontacts)

For Each CurrentItem In objFolder.Items
Debug.Print CurrentItem.FileAs
Next

Set objFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

End Function


I would like to know how to collect this list into a combo box ??

Thanx again
Wayne
 
M

Marc

Hi,
Searching in VBA Access help for combox addItem:
With myControl
.AddItem "First Item", 1
.AddItem "Second Item", 2
.DropDownLines = 3
.DropDownWidth = 75
.ListHeaderCount = 0
End With

so it will become:

Wayne Levin said:
Here is my code which produces the list of contacts.

Public Function ReadContacts()

Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim CurrentItem
Dim strOutput

Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFoldercontacts)

For Each CurrentItem In objFolder.Items
Debug.Print CurrentItem.FileAs
Me!cboboxname.AddItem CurrentItem.FileAs
Next

Set objFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

End Function
Sorry if I'm being dense.
Marc
 
C

Chris Nebinger

Access combo boxes do not have a .AddItem in 2000 or XP.
Instead, you have to have a delimted string of ";"'s to
add to the RowSource

Public Function ReadContacts()

Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim CurrentItem
Dim strOutput
dim strRow As String
Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder
(olFoldercontacts)

For Each CurrentItem In objFolder.Items
strRow = strRow & currentitem.fileas
& ";"
Next
cboBoxName.RowSource = strRow
Set objFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

End Function
 
M

Marc

Chris Nebinger said:
Access combo boxes do not have a .AddItem in 2000 or XP.
Instead, you have to have a delimted string of ";"'s to
add to the RowSource

Public Function ReadContacts()

Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim CurrentItem
Dim strOutput
dim strRow As String
Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder
(olFoldercontacts)

For Each CurrentItem In objFolder.Items
strRow = strRow & currentitem.fileas
& ";"
Next
cboBoxName.RowSource = strRow
Set objFolder = Nothing
Set objNameSpace = Nothing
Set objOutlook = Nothing

End Function
<snip>

Ack. That is what I was looking for. Then why does the help insist in saying
it is there?
Frustrated,
Marc
 
Top