VBA: How to Create a New Contact Item in Outlook with Automation

Article translations Article translations
Article ID: 161012 - View products that this article applies to.
This article was previously published under Q161012
Expand all | Collapse all


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

This article shows you how to use Automation from a Microsoft Access form to start Microsoft Outlook and 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.

For information about how to run Microsoft Schedule+ with Automation, please see the following article in the Microsoft Knowledge Base:
147633 ACC: How to Run Schedule+ from MS Access Using Automation
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.


The following example shows 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 run Microsoft Outlook from a Microsoft Access form, follow these steps:

  1. Open the sample database Northwind.mdb.
  2. Create a new form not based on any table or query in Design view:
          Form: FrmOutlook
          Caption: Outlook Form
          Command button:
             Name: RunOutlook
             Caption: Start Outlook
             OnClick: =StartOutlook()
  3. On the View menu, click Code to open the form module.
  4. On the Tools menu, click References.
  5. Click Microsoft Outlook 8.0 Object Library in the Available References box. If it does not appear in the list, click the Browse button and browse for MSOutl8.olb, which is installed by default in the C:\Program Files\Microsoft Office\Office folder.
  6. Click OK to close the References dialog box.
  7. Type the following procedure in the form's code module:
          Public Function StartOutLook()
             On Error GoTo StartOutLook_Error
             Dim spObj As Object, MyItem As Object
             ' Create a Microsoft OutLook object.
             Set spObj = CreateObject("Outlook.Application")
             ' Create and open new contact form for input.
             ' You can substitute olAppointmentItem, olJournalItem, olMailItem,
             ' olNoteItem, olPostItem, or olTaskItem for olContactItem.
              Set MyItem = spObj.CreateItem(olContactItem)
             ' Quit Microsoft Outlook.
              Set spObj = Nothing
              Exit Function
             MsgBox "Error: " & Err & " " & Error
             Exit Function
          End Function
  8. Close the module and switch the form to Form view.
  9. Click the Start Outlook button. Note that Microsoft Outlook starts and displays a new contact screen.


For more information about using Automation with Microsoft Outlook, please see the following article in the Microsoft Knowledge Base:
160502 ACC: Using Automation to Add Appointments to Microsoft Outlook
For more information about using Automation to work with other programs, search the Help Index for "Automation, overview," or ask the Microsoft Access 97 Office Assistant.


Article ID: 161012 - Last Review: January 19, 2007 - Revision: 3.3
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
  • Microsoft Outlook 97 Standard Edition
kbinfo kbinterop KB161012
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com