Example #1: Delete all phone numbers from address records marked as "Preferred"
Private Sub RaisersEdgeRecord_AfterSave(oRecord As Object)
Dim oCon As CRecord
Set oCon = oRecord
Dim oPhone As CConstitAddressPhone
For Each oPhone In oCon.PreferredAddress.Phones
'Loop through the phone numbers in the Preferred Address
If oPhone.Fields(CONSTIT_ADDRESS_PHONES_fld_PHONETYPE) = "Home" Then
'Delete the phone number if it has a phonetype of Home
oCon.PreferredAddress.Phones.Remove oPhone
End If
Next oPhone
Set oCon = Nothing
Set oPhone = Nothing
End Sub
Example #2: Delete all phone numbers from address records not marked as "Preferred" for a specific constituent.
Private Sub RemoveNonPrefPhones()
Dim oCon As CRecord
Set oCon = New CRecord
oCon.Init REApplication.SessionContext
oCon.Load 280 'load Robert Hernandez record
Dim oAdd As CConstitAddress
Dim oAdds As CConstitAddresses
Set oAdds = oCon.Addresses
Dim oPhones As CConstitAddressPhones
Dim oPhone As CConstitAddressPhone
For Each oAdd In oAdds
Debug.Print "Processing Address Type..." & oAdd.Fields(CONSTIT_ADDRESS_fld_TYPE)
'locate a non-preferred address record
If oAdd.Fields(CONSTIT_ADDRESS_fld_PREFERRED) <> -1 Then
Set oPhones = oAdd.Phones
For Each oPhone In oPhones
Debug.Print "Deleting Phone Type: " & oPhone.Fields(CONSTIT_ADDRESS_PHONES_fld_PHONETYPE)
Debug.Print "Deleting Phone number: " & oPhone.Fields(CONSTIT_ADDRESS_PHONES_fld_NUM)
oPhones.Remove oPhone
Next oPhone
Else: End If
Next oAdd
Set oPhones = Nothing
oCon.Save 'Save change to record or else phone numbers will not be deleted
Set oAdds = Nothing
oCon.Closedown
Set oCon = Nothing
Set oPhone = 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. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.