VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Outlook Contacts as ADO RecordSet

by Brian Gillham (7 Submissions)
Category: Microsoft Office Apps/VBA
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

The purpose of this code is to read the Outlook Contacts Folder into an ADO RecordSet. Often you want to let your app use either the Outlook Contacts or your own. This will give you a jump start.

Code Returns
ADO RecordSet

Rate Outlook Contacts as ADO RecordSet

Sub Outlook_Contacts()
 Dim ADOConn As ADODB.Connection
 Dim ADORS As ADODB.Recordset
 Dim strConn As String
 Set ADOConn = New ADODB.Connection
 Set ADORS = New ADODB.Recordset
 With ADOConn
  'Change the Connection String below
  ' to the correct settings
  .ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Exchange 4.0;MAPILEVEL=Outlook Address Book\;PROFILE=Outlook;TABLETYPE=1;DATABASE=c:\temp"
  .Open
 End With
 With ADORS
  Set .ActiveConnection = ADOConn
  .CursorType = adOpenStatic
  .LockType = adLockReadOnly
  .Open "Select * from [Contacts]"
  .MoveFirst
  'Test: just loop thru the first contact
  Dim i As Long
  For i = 0 To ADORS.Fields.Count - 1
   Debug.Print ADORS(i).Name + _
   vbTab + Format(ADORS(i).Value)
  Next i
  .Close
 End With
 Set ADORS = Nothing
 ADOConn.Close
 Set ADOConn = Nothing
End Sub

Download this snippet    Add to My Saved Code

Outlook Contacts as ADO RecordSet Comments

No comments have been posted about Outlook Contacts as ADO RecordSet. Why not be the first to post a comment about Outlook Contacts as ADO RecordSet.

Post your comment

Subject:
Message:
0/1000 characters