Microsoft KB Archive/209955

= ACC2000: How to Use Automation to Create a New Contact Item in Microsoft Outlook =

Article ID: 209955

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition
 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q209955



This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
This article shows you how to use Automation from a Microsoft Access form to start Microsoft Outlook and to display a new contact screen for input. You can change just one line of code to make this example apply to a new Microsoft Outlook appointment, journal entry, mail message, note, post, or task.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example shows you how to create a form in Microsoft Access that starts Microsoft Outlook from a command button. Then the Automation code opens a new contact screen for input in Microsoft Outlook. After you enter the contact and save and close the contact form, the Automation code quits Microsoft Outlook and returns to the Microsoft Access form.

To create a new contact item in Microsoft Outlook from a Microsoft Access form, follow these steps:  Open the sample database Northwind.mdb.  Create a new form that is not based on any table or query, add a command button the form, and make the following property assignments:   Form: (save as frmOutlook) Caption: Add to Outlook Form

Command button: --  Name: cmdOutlook Caption: Start Outlook OnClick: =fncStartOutlook  On the View menu, click Code to open the Visual Basic Editor. On the Tools menu, click References. Click Microsoft Outlook 9.0 Object Library in the Available References list. If the library does not appear in the list, click Browse and browse to the Msoutl9.olb file. This file is installed by default in the C:\Program Files\Microsoft Office\Office folder. Click OK to close the References dialog box.</li>  Type or paste the following procedure: Option Compare Database Option Explicit

Public Function fncStartOutLook On Error GoTo StartError

Dim objOutlook As Object Dim objItem As Object

'Create a Microsoft Outlook object. Set objOutlook = CreateObject("Outlook.Application")

'Create and open a new contact form for input. Set objItem = objOutlook.CreateItem(olContactItem)

'   'To create a new appointment, journal entry, email message, note, post, 'or task, replace olContactItem above with one of the following: '   '  Appointment = olAppointmentItem 'Journal Entry = olJournalItem 'Email Message = olMailItem '        Note = olNoteItem '        Post = olPostItem '        Task = olTaskItem '   objItem.Display

'Quit Microsoft Outlook. Set objOutlook = Nothing Exit Function

StartError: MsgBox "Error: " & Err & " " & Error Exit Function End Function </li> On the File menu, click Close and Return to Microsoft Access, and switch the form to Form View.</li> Click Start Outlook. Note that Microsoft Outlook displays a new contact screen.</li></ol>

<div class="references_section">