Public Sub PhoneClause()

   Dim sSQLPhone As String

   Dim sPhoneNumber As String

   

   Dim oRecords As CRecords

   Dim oRecord As CRecord

   

   'The following statement will return any constituent that has the specified number

   'on any address for any phone type - sPhoneNumber could be a passed in variable

   sPhoneNumber = "303-997-3301"

   sSQLPhone = "RECORDS.ID in (SELECT RECORDS.ID FROM " & _

              "((RECORDS INNER JOIN CONSTIT_ADDRESS ON " & _

              "RECORDS.ID = CONSTIT_ADDRESS.CONSTIT_ID) INNER JOIN " & _

              "CONSTIT_ADDRESS_PHONES ON CONSTIT_ADDRESS.ID = " & _

              "CONSTIT_ADDRESS_PHONES.CONSTITADDRESSID) INNER JOIN " & _

              "PHONES ON CONSTIT_ADDRESS_PHONES.PHONESID = PHONES.PHONESID " & _

              "WHERE (((PHONES.NUM)='" & sPhoneNumber & "')) AND (((RECORDS.IS_CONSTITUENT) = -1)))"

   

   Set oRecords = New CRecords

   oRecords.Init REApplication.SessionContext, tvf_record_CustomWhereClause, sSQLPhone

   

   For Each oRecord In oRecords

       MsgBox oRecord.Fields(RECORDS_fld_FIRST_NAME) & " " & oRecord.Fields(RECORDS_fld_LAST_NAME)

       oRecord.CloseDown

   Next oRecord

   

   Set oRecord = Nothing

   

   oRecords.CloseDown

   Set oRecords = Nothing

   

End Sub

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Our Customer Support can help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality. If you are interested in learning more about the VBA and API modules, contact your account manager.