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.
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.
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:
Open the sample database Northwind.mdb.
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()
On the View menu, click Code to open the form module.
On the Tools menu, click References.
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.
Click OK to close the References dialog box.
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
Close the module and switch the form to Form view.
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, 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.