For versions 7.6 to 7.71:

Public Sub AddRelation()



  Dim oRecRelation As CRecord

  Dim orecOrg As CRecord

  Dim oMainREc As CRecord

  Dim ID As Long ' Individual Relationship ID

  Dim lID As Long ' Organization relationship ID

  

  Set oRecRelation = New CRecord

  Set orecOrg = New CRecord

  

  'Get the Organization relationship information and save it

  With orecOrg

      .Init REApplication.SessionContext

      .Fields(RECORDS_fld_KEY_INDICATOR) = 1

      .Fields(RECORDS_fld_ORG_NAME) = "Blackbaud"

      .Save

      lID = .Fields(RECORDS_fld_ID)

      .CloseDown

  End With

  

  '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"

  'The following line prevents the creation of a new constituent record when = FALSE

       .Fields(RECORDS_fld_IS_CONSTITUENT) = False

      .Save

      ID = .Fields(RECORDS_fld_ID)

      .CloseDown

  End With

  

  Set oRecRelation = Nothing

  Set orecOrg = Nothing

  

  Set oMainREc = New CRecord

  oMainREc.Init REApplication.SessionContext

  

  oMainREc.Load 280

  

  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

          .Save

          .CloseDown

      End With

      

      Set oInd = Nothing

      'link the main record with the organization relationship

   Dim oOrg As COrganization2

   Set oOrg = New COrganization2

   oOrg.Init REApplication.SessionContext

      With oOrg

           .Fields(ORGANIZATION2_fld_CONSTIT_ID) = oMainREc.Fields(RECORDS_fld_ID)

          .Fields(ORGANIZATION2_fld_RELATION_ID) = lID

          'Make this organization the Primary Org Constituent must be employee

          .Fields(ORGANIZATION2_fld_IS_EMPLOYEE) = True

          .Fields(ORGANIZATION2_fld_IS_PRIMARY) = True

          .Save

      End With

   

  oMainREc.CloseDown

  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. 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.