Compartilhar via


Searching for Contacts

Topic Last Modified: 2006-06-11

When using the CDO Person object, you can search contacts for specific properties and fields. For example, a recruiter may want to search a contact list for candidates who live in California.

Example

The following example uses the CDO Person object to search for candidates who live in California.

Example

Visual Basic

'////////////////////////////////////////////////////////////////////////////////////////////////////
'//Function: SearchContacts
'//Purpose: Searches through the contacts folder of a specified mail-directory for candidates who
'//         live in California.
'//Input/Output:
'// strWhereClause = Contains the Where clause of the SQL search string.
'// iMbx = the Mailbox which contains the contacts folder to be searched.
'// Conn = the active ADODB Connection object for the contacts folder to be searched.
'//Notes:
'////////////////////////////////////////////////////////////////////////////////////////////////////

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Function SearchContacts( strWhereClause as String, iMbx as CDO.IMailbox, Conn as ADODB.Connection )

  Dim Rs as New ADODB.Recordset
  Set Rs.ActiveConnection = Conn

  strSQL = "select ""DAV:href"", " & _
                   """urn:schemas:contacts:fileas"", " & _
                   """urn:schemas:contacts:email1""" & _
                   "from "

  strSQL = strSQL & """" & iMbx.Contacts & """ "
  strSQL = strSQL & strWhereClause

  Rs.Open strSQL, Conn

End Function