Public Sub AddRelationship()



  Dim oRec As CRecord

  Dim lID As Long

  Dim iRelation As CRecord

  Dim oInd As CIndividual2

  

  Set oRec = New CRecord

  oRec.Init REApplication.SessionContext

  'load Organization Record AAA Concrete

  

  oRec.Load 565

  

  'create relationship record

  Set iRelation = New CRecord

  With iRelation

      .Init REApplication.SessionContext

      .Fields(RECORDS_fld_IS_CONSTITUENT) = False

      .Fields(RECORDS_fld_LAST_NAME) = "Doe"

      .Fields(RECORDS_fld_FIRST_NAME) = "Jane"

      .Fields(RECORDS_fld_TITLE_1) = "Mrs."

      .Save

      lID = iRelation.Fields(RECORDS_fld_ID)

      .CloseDown

  End With

  Set iRelation = Nothing

  

  Dim lAddID As Long

  

  'add Relationship to organization

  Set oInd = New CIndividual2

  oInd.Init REApplication.SessionContext

  

  With oInd

      .Fields(INDIVIDUAL2_fld_CONSTIT_ID) = oRec.Fields(RECORDS_fld_ID)

      .Fields(INDIVIDUAL2_fld_RELATION_ID) = lID

      .Fields(INDIVIDUAL2_fld_IS_CONTACT) = True

      .Fields(INDIVIDUAL2_fld_CONTACT_TYPE) = "Primary"

      .Save

      

      'Breaks link with org. address and adds new address

      .Address.Links.BreakLink .Address.Fields(CONSTIT_ADDRESS_fld_ID)

      .Address.Fields(CONSTIT_ADDRESS_fld_ADDRESS_BLOCK) = "2000 Daniel Island Drive"

      .Address.Fields(CONSTIT_ADDRESS_fld_CITY) = "Charleston"

      .Address.Fields(CONSTIT_ADDRESS_fld_POST_CODE) = "29492"

      

      'Adds phone number

      With .Address.Phones.Add

      .Fields(CONSTIT_ADDRESS_PHONES_fld_PHONETYPE) = "Home"

      .Fields(CONSTIT_ADDRESS_PHONES_fld_NUM) = "8004688996"

      oInd.Save

      End With

      

      .Save

      .CloseDown

  End With

  

  'Cleanup

  Set oInd = Nothing

  oRec.Save

  oRec.CloseDown

  Set oRec = 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.