ACC97: Sample Procedure to Attach a Microsoft Outlook Folder

ID: Q161174

The information in this article applies to:

SUMMARY

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

This article shows you how to create 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:

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: You can open a table that is linked to a Microsoft Outlook or Microsoft Exchange folder if that table's Connect property doesn't contain a profile parameter. However, when you open the table, you may have to supply profile information multiple times instead of just once.

1. Open the sample database Northwind.mdb.

2. 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

3. 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          : kbole kbusage IsmOthr 
Version           : 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto

Last Reviewed: November 21, 1998