Building a Recordset of Contacts Info from Outlook:   Return to List

' You will need to add a refrence to Microsoft Active Data Object 2.x.

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Long

Set con = New ADODB.Connection
Set rs = New ADODB.Recordset

With con
    .ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
        "Exchange 4.0;" & _
        "MAPILEVEL=Outlook Address Book\;" & _
        "PROFILE=Outlook;" & _
        "TABLETYPE=1;" & _
        "DATABASE=c:\temp" 'You will need to change this!
    .Open
End With

With rs
    Set .ActiveConnection = con
    .CursorType = adOpenStatic
    .LockType = adLockReadOnly
    .Open "Select * from [Contacts]"
    .MoveFirst
    Do While Not rs.EOF
        For i = 0 To rs.Fields.Count - 1
            Debug.Print rs(i).Name + vbTab + Format(rs(i).Value)
        Next i
        rs.MoveNext
    Loop
    .Close
End With

Set rs = Nothing
con.Close



Note to Webmaster