ACC97: Exchange/Outlook Driver Example Incorrect in Acread80.wri

ID: Q163067


The information in this article applies to:


SYMPTOMS

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

In the Microsoft Access 97 Readme file, Acread80.wri, the following code sample in the Microsoft Exchange/Outlook Driver section is incomplete:


   To open a Microsoft Exchange/Outlook folder directly, use the
   OpenDatabase method and specify values for the following parts:
   database, options = True, read-only = True, and a dbname data source.
   The following code example uses the OpenDatabase method to open a
   Microsoft Exchange/Outlook folder named Barbara and count the number of
   messages received from a user named Jim Harris:

      Public Sub OpenExchangeFolder()
         Dim dbsExchange As Database, intCount As Integer
         Dim rst As Recordset, str As String
         str = "Exchange 4.0;MAPILEVEL=" _
            & "Dave Jones (Exchange)|People\Important;TABLETYPE=0;"
         Set dbsExchange = OpenDatabase _
            ("C:\Data\Temp.mdb", 0, 0, str)
         Set rst = dbsExchange.OpenRecordset("Barbara")
         rst.MoveFirst
         While Not rst.EOF
            If rst!From = "Jim Harris" Then
               intCount = intCount + 1
            End If
            rst.MoveNext
         Wend
         rst.Close
         dbsExchange.Close
      End Sub 


RESOLUTION

The Database and Profile arguments are missing from the str variable in the code example, which is used as the connect parameter for the OpenDatabase method. The Database argument indicates the Microsoft Access database in which to open the Microsoft Outlook/Exchange recordset; the Profile argument indicates the Microsoft Outlook/Exchange profile to use when you open the recordset. You can view the profiles you have set up on your computer by double-clicking the Mail icon in Control Panel. When the Microsoft Outlook Properties dialog box appears, click Show Profiles.

NOTE: You can download the Exchange/Outlook Wizards from Microsoft's Web site on the Internet. The wizard enables you to import or link to Microsoft Exchange/Outlook data without writing Visual Basic code. The wizards are available at http://www.microsoft.com/accessdev/a-free.htm.

Modify the example to include the Database and Profile arguments:


   Public Sub OpenExchangeFolder()

      Dim dbsExchange As Database, intCount As Integer
      Dim rst As Recordset, str As String
      str = "Exchange 4.0;MAPILEVEL=" _
         & "Dave Jones (Exchange)|People\Important;TABLETYPE=0;" _
         & "DATABASE = C:\Data\Temp.mdb;PROFILE = Microsoft Outlook"
      Set dbsExchange = OpenDatabase _
         ("C:\Data\Temp.mdb", 0, 0, str)
      Set rst = dbsExchange.OpenRecordset("Barbara")
      rst.MoveFirst
      While Not rst.EOF
         If rst!From = "Jim Harris" Then
            intCount = intCount + 1
         End If
         rst.MoveNext
      Wend
      rst.Close
      dbsExchange.Close

   End Sub 


MORE INFORMATION

If you want to link the Microsoft Outlook/Exchange folder as a table in your database and not just open it in code, the following sample code shows you how.

Linking to a Personal Folder


   ' This procedure links a personal address book.

     Sub LinkPersonalFolder()
     Dim dbsCurrent As Database
     Dim tdfAddress As Tabledef

   ' Open the Jet database.

     Set dbsCurrent = DBEngine.Workspaces(0).OpenDatabase _
     ("C:\My Documents\Example.mdb")

   ' Create a table definition for the Exchange table.

     Set tdfAddress = dbsCurrent.CreateTableDef("Personal Addresses")

   ' Provide the name of the Exchange file with the Connect property.

     tdfAddress.Connect = "Exchange 4.0;MAPILEVEL=Personal Folders|;" _
     & "TABLETYPE=1;DATABASE=C:\My _
        Documents\Example.mdb;PROFILE=MyProfile"

   ' Provide the name of the table with the SourceTableName property.

     tdfAddress.SourceTableName = "Personal Address Book"

   ' Append the TableDef to the TableDefs collection to create the link.

     dbsCurrent.TableDefs.Append tdfAddress

     End Sub 

Linking to a Folder in Your Mailbox


   ' This procedure links to a mailbox folder called Student Info.
     Sub LinkStudentFolder
     Dim dbsCurrent As Database
     Dim tdfStudent As Tabledef

   ' Open the Jet database.
     Set dbsCurrent = DBEngine.Workspaces(0).OpenDatabase _
     ("C:\My Documents\Example.mdb")

   ' Create a table definition for the Exchange table.
     Set tdfStudent = dbsCurrent.CreateTableDef("Student Folder")

   ' Provide the name of the Exchange file with the Connect property.
     tdfStudent.Connect = "Exchange 4.0;MAPILEVEL=Mailbox - Nancy _
        Davolio|;" _
        & "TABLETYPE=0;DATABASE=C:\My _
        Documents\Example.mdb;PROFILE=MyProfile"

   ' Provide the name of the table with the SourceTableName property.
     tdfStudent.SourceTableName = "Student Info"

   ' Append the TableDef to the TableDefs collection to create the link
     dbsCurrent.TableDefs.Append tdfStudent.

     End Sub 

Linking to a Public Folder


   ' This procedure links to a public folder called School Info.
     Sub LinkStudentInfo
     Dim dbsCurrent As Database
     Dim tdfSchoolInfo As Tabledef

   ' Open the Jet database.
     Set dbsCurrent = DBEngine.Workspaces(0).OpenDatabase _
     ("C:\My Documents\Example.mdb")

   ' Create a table definition for the Exchange table.
     Set tdfSchoolInfo = dbsCurrent.CreateTableDef("School Information")

   ' Provide the name of the Exchange file with the Connect property.
     tdfSchoolInfo.Connect = "Exchange 4.0;MAPILEVEL=Public Folders|;" _
     & "TABLETYPE=0;DATABASE=C:\My _
        Documents\Example.mdb;PROFILE=MyProfile"

   ' Provide the name of the table with the SourceTableName property.
     tdfSchoolInfo.SourceTableName = "School Info"

   ' Append the TableDef to the TableDefs collection to create the link.
     dbsCurrent.TableDefs.Append tdfSchoolInfo

     End Sub 


REFERENCES

For more information about using the OpenDatabase method to connect to a Microsoft Outlook/Exchange folder, search the Help Index for "OpenDatabase Method."

For more information about the Microsoft Outlook/Exchange connect argument, search the Help Index for "Connect property."

For more examples of linking a Microsoft Outlook/Exchange folder as a Microsoft Access 97 table, please see the following article in the Microsoft Knowledge Base:

Q161174 ACC97: Sample Procedure to Attach a Microsoft Outlook Folder

Additional query words: attach mail mapi


Keywords          : DcmOthr 
Version           : 97
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: April 22, 1999