Public Sub AddSpousetoNewRecord()

   Dim oConstit As CRecord
   Dim oSpouse As CRecord
   Dim oRelation As CIndividual2
   Dim lID As Long

   Set oConstit = New CRecord

   With oConstit
       .Init REApplication.SessionContext
       .Fields(RECORDS_fld_FIRST_NAME) = "John"
       .Fields(RECORDS_fld_LAST_NAME) = "Doe"
       .PreferredAddress.Fields(CONSTIT_ADDRESS_fld_ADDRESS_BLOCK) = "123 Main Street"
       .PreferredAddress.Fields(CONSTIT_ADDRESS_fld_STATE) = "SC"
       .PreferredAddress.Fields(CONSTIT_ADDRESS_fld_CITY) = "Charleston"
   End With 

   Set oSpouse = New CRecord

   With oSpouse
       .Init REApplication.SessionContext
       .Fields(RECORDS_fld_IS_CONSTITUENT) = False
       .Fields(RECORDS_fld_LAST_NAME) = "Doe"
       .Fields(RECORDS_fld_FIRST_NAME) = "Jane"
       .Fields(RECORDS_fld_PRIMARY_ADDRESSEE) = "Mrs. Jane Doe"
       .Fields(RECORDS_fld_PRIMARY_SALUTATION) = "Jane Doe"

       lID = .Fields(RECORDS_fld_ID)


   End With

   Set oSpouse = Nothing 

   'add Relationship to constituent
   Set oRelation = New CIndividual2

   oRelation.Init REApplication.SessionContext

   With oRelation
       .Fields(INDIVIDUAL2_fld_CONSTIT_ID) = oConstit.Fields(RECORDS_fld_ID)
       .Fields(INDIVIDUAL2_fld_RELATION_ID) = lID
       .Fields(INDIVIDUAL2_fld_IS_SPOUSE) = True
       'linking address with constituent address
       .Address.Fields(CONSTIT_ADDRESS_fld_ADDRESS_ID) = oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_ADDRESS_ID)
       .Address.Fields(CONSTIT_ADDRESS_fld_LINKED) = True


   End With

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