ACC2000: How to Use Automation to Create a New Contact Item in Microsoft Outlook (209955)



The information in this article applies to:

  • Microsoft Access 2000
  • Microsoft Outlook 2000

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:
  1. Open the sample database Northwind.mdb.
  2. 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()
    					
  3. On the View menu, click Code to open the Visual Basic Editor.
  4. On the Tools menu, click References.
  5. 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.
  6. Click OK to close the References dialog box.
  7. 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
    					
  8. On the File menu, click Close and Return to Microsoft Access, and switch the form to Form View.
  9. Click Start Outlook. Note that Microsoft Outlook displays a new contact screen.

REFERENCES

For additional information about using Automation with Microsoft Outlook, please see the following articles in the Microsoft Knowledge Base:

209963 ACC2000: How to Use Automation to Add Appointments to Microsoft Outlook

209932 ACC2000: How to Use Automation to Add a Task or a Reminder to Microsoft Outlook

For more information about using Automation to work with other programs, click Microsoft Access Help on the Help menu, type Automation, overview in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbinfo kbinterop KB209955