VB icon

Outlook Contacts as ADO RecordSet

Email
Submitted on: 1/23/2015 1:21:00 AM
By: Brian Gillham (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB 5.0, VB 6.0
Views: 762
 
     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:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Outlook Contacts as ADO RecordSet
' Description: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.
' By: Brian Gillham (from psc cd)
'
' Returns: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


Other 5 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.