ACC97: Sample Procedure to Attach a Microsoft Outlook Folder

Last reviewed: August 29, 1997
Article ID: Q161174
The information in this article applies to:
  • Microsoft Access 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article contains a sample procedure to link a Microsoft Outlook folder as a table in a Microsoft Access database.

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 the "Building Applications with Microsoft Access 97" manual.

MORE INFORMATION

The example in this article uses the Microsoft Messaging Driver, which you can install from the Microsoft Data Access Pack in the Office 97 ValuPack. For more information about obtaining and installing the Microsoft Messaging Driver, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q159322
   TITLE     : ACC97: Paradox, Lotus, & MS Exchange/Outlook ISAMs in
               ValuPack

   ARTICLE-ID: Q161173
   TITLE     : ACC97: MS Exchange ISAM Driver Requires Manual Registration

The Microsoft Messaging Driver gives you programmatic access to Microsoft Outlook and Microsoft Exchange mail items. Note that you cannot use this driver through the user interface in Microsoft Access 97. You must use it in a Visual Basic for Applications procedure.

There are some issues to consider when you use a linked Microsoft Outlook folder in Microsoft Access:

  • You cannot select which fields appear in the linked table; a subset of the total number of Microsoft Outlook fields appears in the table, and they are pre-programmed in the Microsoft Messaging Driver. However, you can rearrange or hide the fields in Datasheet view of the table to customize its appearance.
  • You can add and delete records, but you cannot modify any records in the table.
  • You cannot enter data into some fields in the linked table, even when you are adding a new record.
  • If items in the linked Microsoft Outlook folder use a special form, you must enter the correct form type in the Message Class field when you add new records to the table. If you do not specify a Message Class, Microsoft Outlook uses the default mail form to display your data. The Message Classes for the standard Microsoft Outlook folders are:

          Folder       Message Class
          ----------------------------
          Calendar     IPM.Appointment
          Contacts     IPM.Contact
          Inbox        IPM.Note
          Journal      IPM.Activity
          Notes        IPM.StickyNote
          Tasks        IPM.Task
    
    
The following sample procedure creates a table linked to a folder in a Microsoft Outlook mailbox. To use the procedure, you must do the following:
  • Set up Microsoft Outlook on your computer.
  • Set the SourceTableName property in the procedure to the name of the mail folder you want to attach to your database.
  • Substitute valid Connect property parameters for the linked table in the procedure:

          Parameter     Value
          --------------------------------------------------------------------
          MAPILEVEL     The path to the parent of the folder you want to link.
    
          DATABASE      The path and file name of the current database.
    
          PROFILE       A valid Microsoft Outlook or Microsoft Exchange
                        profile.
    
    

  • Open the sample database Northwind.mdb.

  • Create a module and type the following procedure:

          Function AttachMail()
          Dim db As Database
          Dim td As TableDef
          On Error GoTo Errorhandler
    
             Set db = CurrentDb()
             Set td = db.CreateTableDef("tblInbox")
    
             ' Substitute your own MAPILEVEL, DATABASE and PROFILE arguments.
             td.Connect = "Exchange 4.0;MAPILEVEL=Mailbox - Nancy Davolio|;"
             td.Connect = td.Connect & "DATABASE=C:\Program Files\Microsoft "
             td.Connect = td.Connect & "Office\Office\Samples\Northwind.mdb;"
             td.Connect = td.Connect & "PROFILE=Microsoft Outlook"
    
             ' Substitute the name of the folder you want to attach.
             td.SourceTableName = "Inbox"
    
             db.TableDefs.Append td
             Application.RefreshDatabaseWindow
             MsgBox "Table Appended!"
          Exit Function
          Errorhandler:
             Msgbox "Error " & Err & " " & Error
             Exit Function
          End Function
    
    

  • Press CTRL+G to open the Debug window, type the following line, and then press ENTER:

         ?AttachMail()
    

    After the procedure runs, the Inbox mail folder appears as a linked, read-only table in the database.

    REFERENCES

    For more information about using the Microsoft Messaging Driver, refer to the Microsoft Exchange/Outlook Driver section of the Acread80.wri file in the C:\Program Files\Microsoft Office\Office folder.

    For more information about setting the Connect property for a linked Microsoft Exchange/Microsoft Outlook mail folder, search the Help index for "Connect property."


Additional query words: mail mapi mailbox
Keywords : AutoGnrl kbole kbusage PgmHowTo IsmOthr
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.