Datasheet

Book IX
Chapter 1
Automation with Other
Office Programs
669
Adding a Contact to Outlook
In the next few sections, you’ll see how Access can share information with
Outlook, Word, and Excel — oh my!
Adding a Contact to Outlook
Suppose you’re working on an Access program and your users suggest that
it would be a good idea to include in your program the capability to add
a contact from your Access database to the Microsoft Outlook contacts.
You could be mean and tell them to just type it in themselves, or you can
impress them by adding a button to a form that adds the current contact to
their Outlook contacts.
Consider the form shown in Figure 1-3. This form is a basic customer contact
form that you might find in one of your applications, with one exception —
the addition of an Add to Outlook Contacts button.
Figure 1-3:
Changing
an Access
form to add
a contact to
Outlook.
Now just adding the button doesn’t accomplish much; you have to add code
to the button’s Click event procedure. In the form’s Design view, double-
click the button to show the Property sheet, click the Event tab, click the
ellipsis button on the right of the On Click event property, and then click
Code Builder to open the Visual Basic Editor to the button’s Click event
procedure. The code looks something like this:
Private Sub cmdOutlook_Click()
‘Open Instance of Microsoft Outlook
Dim Olk As Outlook.Application
Set Olk = CreateObject(“Outlook.Application”)
‘Create Object for an Outlook Contact
Dim OlkContact As Outlook.ContactItem
Set OlkContact = Olk.CreateItem(olContactItem)
44_532188-bk09ch01.indd 66944_532188-bk09ch01.indd 669 3/29/10 10:59 PM3/29/10 10:59 PM