You are currently offline, waiting for your internet to reconnect

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

This article was previously published under Q161012
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.
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article shows you how to use Automation from a Microsoft Accessform to start Microsoft Outlook and display a new contact screen forinput. You can change just one line of code to make this example apply toa 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:
147633ACC: How to Run Schedule+ from MS Access Using Automation
This article assumes that you are familiar with Visual Basic forApplications and with creating Microsoft Access applications using theprogramming tools provided with Microsoft Access. For more informationabout Visual Basic for Applications, please refer to your version of the"Building Applications with Microsoft Access" manual.
MORE INFORMATION
The following example shows how to create a form in Microsoft Access thatstarts Microsoft Outlook from a command button. Then, the Automation codeopens a new contact screen for input in Microsoft Outlook. After you enterthe contact, and save and close the contact form, the Automation codequits 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)          MyItem.Display         ' Quit Microsoft Outlook.          Set spObj = Nothing          Exit Function      StartOutLook_Error:         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.
REFERENCES
For more information about using Automation with Microsoft Outlook, pleasesee 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 MicrosoftAccess 97 Office Assistant.
OutSol OutSol97
Properties

Article ID: 161012 - Last Review: 01/19/2007 20:51:38 - Revision: 3.3

  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
  • Microsoft Outlook 97 Standard Edition
  • kbinfo kbinterop KB161012
Feedback