Opening Outlook address book from Access form

J

Jack

Hi,
I need to maintain an Access application written by somebody else. We got a
form where there is a dropdown that has a list of user name. By the side of
this dropdown there is a send button. When a users chooses a dropdown contact
list and clicks send outlook form opens up with the corresponding fields
filled up in accordance with the following code:
Private Sub cmdCoOrdinator_Click()
On Error GoTo Err_cmdCoOrdinator_Click

If IsNull(txtcoordinator) Then GoTo Err_cmdCoOrdinator_email

Dim appOL As Outlook.Application
Dim testEmail As Outlook.MailItem

Set appOL = Outlook.Application
Set testEmail = appOL.CreateItem(olMailItem)

testEmail.Subject = "CAR-PAR# " & txtIDNum.Value
testEmail.To = txtcoordinator.Value
testEmail.body = cboCoOrdinator.Column(1) & ", a CAR-PAR has been issued for
" & cboPlants.Value & " that needs your attention."

'Display the email so you can amend details.
testEmail.Display

' this works, it causes a message box to pop up in Outlook saying an outside
program may be sending a virus
'testEmail.Send

'Clear the reference to the objects as we no longer need them.
Set testEmail = Nothing
Set appOL = Nothing

Exit_cmdCoOrdinator_Click:
Exit Sub

Err_cmdCoOrdinator_Click:
MsgBox Err.Description
Resume Exit_cmdCoOrdinator_Click

Err_cmdCoOrdinator_email:
If IsNull(txtcoordinator) Then MsgBox "You must select a name first!"


End Sub

Now I need to change the dropdown and instead with some trick get the
outlook address book to display and have the user choose the address from the
address book and then send the email.

I have not much of idea about how Access utilized Outlook email. Any help is
highly appreciate. Thanks in advance.
 
R

Ralph

Looking at your code I see the following:

' this works, it causes a message box to pop up in Outlook saying an outside
program may be sending a virus
'testEmail.Send

Depending on the size of your address list you can loop through the entries
in the address book and populate the combo box. If your adress book contains
more than a 100 records this probably is not the best idea. In addition the
user will need to 'Allow Access' just like the message you have listed above
about sending a virus.

With Access you can link to an Exchange address book with the 'Link
Exchange/Outlook Wizard' however this connection will likely be very slow. If
the linked table is not too large you may be able to make a copy of the
linked table periodically depending on how often employees are added or
deleted.

Hope this makes sense.
 
J

Jack

Thanks for your help Ralph. I appreciate it very much. Is there any way in
Access to open Outlook Global Address box by click of a button and then to
populate a text box based on click of the name of the Global Address box?
Thanks.
 
R

Ralph

Set a reference to Micorsoft CDO 1.21 Library

Dim oSession As MAPI.Session
Dim oRecipients As MAPI.Recipients
Dim oRecipient As MAPI.Recipient

Set oSession = CreateObject("Mapi.Session")
oSession.Logon GetNamespace("Mapi").CurrentUser, "", False, False, 0
Set oRecipients = oSession.AddressBook(, Title:="Select Address")

For Each oRecipient In oRecipients
Debug.Print oRecipient.Name
Next
 

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