EXAMPLE: Accessing Outlook folders with ADODB

J

Jim Vierra

Sub TestFunction()
OpenOutlookFolder "Outlook", "Personal Folders", "c:\temp"
End Sub

Sub OpenOutlookFolder(strProfile As String, strPSTFolder As String, strDataBase As String)
'Arguments
' strProfile - Outlook profile name
' strPSTFolder - Outlook PST folder name
' strDatabaseTemp - database temporary folder
Dim strOutlook As String
strOutlook = "Outlook 9.0;"

Dim strMAPILevel As String
strMAPILevel = "MAPILEVEL=" & strPSTFolder & "|;" 'Ends with a PIPE char

Dim strTableType As String
strTableType = "TABLETYPE=0;"

strProfile = "PROFILE=" & strProfile & ";"
strDataBase = "DATABASE=" & strDataBase & ";"

Dim oConn As New ADODB.Connection
With oConn
.Provider = "Microsoft.JET.OLEDB.4.0"
.ConnectionString = strOutlook & strProfile & strMAPILevel & strDataBase
.Open
End With

' we can now use SQL to get a recordset of any folder
' contained in the PST.
' Folders within folders can be walked recursively
' as an example we will return the contacts folder
Dim oRS As New ADODB.Recordset
With oRS
.Open "Select * from Contacts", oConn, adOpenStatic, adLockReadOnly
.MoveFirst
Debug.Print oRS(3).Name, oRS(3).Value
Debug.Print oRS(10).Name, oRS(10).Value
.Close
End With

Set oRS = Nothing
oConn.Close
Set oConn = 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