Public Sub AddRelation()

  Dim oRecRelation As CRecord
  Dim oMainREc As CRecord
  Dim id As Long ' Individual Relationship ID
  Dim lID As Long ' Organization relationship ID
  Set oRecRelation = New CRecord

  'Get the Individual relationship information and save it
  With oRecRelation
      .Init REApplication.SessionContext
      .Fields(RECORDS_fld_FIRST_NAME) = "John"
      .Fields(RECORDS_fld_LAST_NAME) = "Doe"
      .Fields(RECORDS_fld_BIRTH_DATE) = "1/23/02"
      id = .Fields(RECORDS_fld_ID)
  End With
  Set oRecRelation = Nothing
  Set oMainREc = New CRecord
  oMainREc.Init REApplication.SessionContext
  'Load the Org Record
  oMainREc.Load 565
  Dim oInd As CIndividual2
  Set oInd = New CIndividual2
  oInd.Init REApplication.SessionContext
  'link the main record to the individual relationship
      With oInd
           .Fields(INDIVIDUAL2_fld_CONSTIT_ID) = oMainREc.Fields(RECORDS_fld_ID)
          .Fields(INDIVIDUAL2_fld_RELATION_ID) = id
          .Address.Fields(CONSTIT_ADDRESS_fld_ADDRESS_BLOCK) = "Street"
          .Address.Links.BreakLink (.Fields(INDIVIDUAL2_fld_ID))
           Dim oPhone As CConstitAddressPhone
           'Loop through the phone numbers and delete the one with a type of Business so the new business number can be added.
           For Each oPhone In .Address.Phones
               If oPhone.Fields(CONSTIT_ADDRESS_PHONES_fld_PHONETYPE) = "Business" Then
                  .Address.Phones.Remove oPhone
               End If
           Next oPhone
          'Add the new phone number
           With .Address.Phones.Add
              .Fields(CONSTIT_ADDRESS_PHONES_fld_PHONETYPE) = "Business"
              .Fields(CONSTIT_ADDRESS_PHONES_fld_NUM) = "1234567890"
           End With
      End With
      Set oInd = Nothing
  Set oMainREc = 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.