Article ID: 163067
Article Last Modified on 1/19/2007
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
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
' 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
' 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
' 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
Additional query words: attach mail mapi
Keywords: KB163067