EXAMPLE:Accessing Outlook Folders with ADOX

J

Jim Vierra

The following is a fix of some of the examples in the KB articles. It addreses the fundamentals of ADOX access to the Outlook folders and PSTs. I believe it is a bit more informative than the MS Examples. I have made some note to point out hte more interesting and at times confusing features of Jet 4.0 connection strings. The string breakdown to VBA code makes it more convenient to modifu the strings.

The order of the provider properties, those things with an equal sign in the middle and separated by a semicolon, is not important. ADO loads these into a set of internal properties before making a connection and then uses them as it requires them. If a critical property is missing or wrong an exception will be thrown.

Sub test()
' send Profile name, and temp file location to use
DisplayOutlookFolders "Outlook", "Personal Folders", "f:\temp\test.tmp"
End Sub

Sub DisplayOutlookFolders(strProfile As String, strPSTFileName As String, strTempDBFile As String)
' Arguments
' strProfile is the Outlook Mail Profile name
' strPSTFileName is the display name of the PST file of interest
' strTemDBFile is the pathname of a temporary file for building the database.
.
Dim cat As ADOX.Catalog
Dim strDataBase As String
Dim strConnection As String
Dim strMAPILevel As String


' this is the provider for Outlook - May be 8.0 for earlier versions
strProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Outlook 9.0;"

' we need to set up the properties and formats them
' all property string terminate with a semicolon
strDataBase = "Database=" & strTempDBFile & ";"
strProfile = "PROFILE=" & strProfile & ";"
strMAPILevel = "MAPILEVEL=" & strPSTFileName & "|;" 'PST store name ends with PIPE

' get top folders (Table type 0)
' here we use an empty MAPILEVEL=;
Set cat = New ADOX.Catalog
strTabletype = "TABLETYPE=0;" ' type for folders
cat.ActiveConnection = strProvider & "MAPILEVEL=;" & strProfile & strTabletype & strDataBase
Debug.Print "PST FOLDERS:"
For Each tbl In cat.Tables
Debug.Print " " & tbl.Name
Next tbl
Set cat.ActiveConnection = Nothing

' get folders in requested store
Set cat = New ADOX.Catalog
strTabletype = "TABLETYPE=0;" ' type for folders
cat.ActiveConnection = strProvider & strMAPILevel & strProfile & strTabletype & strDataBase
Debug.Print "FOLDERS IN:" & strPSTFileName
For Each tbl In cat.Tables
Debug.Print " " & tbl.Name
Next tbl
Set cat.ActiveConnection = Nothing

' now lets do the same for address books
' only the TABLETYPE changes
'Set cat = New ADOX.Catalog
strTabletype = "TABLETYPE=1;" 'type for address books
cat.ActiveConnection = strProvider & strMAPILevel & strProfile & strTabletype & strDataBase
Debug.Print "ADDRESS BOOKS:"
For Each tbl In cat.Tables
Debug.Print " " & tbl.Name
Next tbl

Set cat.ActiveConnection = Nothing
Set cat = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top