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"
       .Save
   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_EDIT) = True
       .Fields(RECORDS_fld_PRIMARY_ADDRESSEE) = "Mrs. Jane Doe"
       .Fields(RECORDS_fld_PRIMARY_SALUTATION_EDIT) = True
       .Fields(RECORDS_fld_PRIMARY_SALUTATION) = "Jane Doe"
       .Save

       lID = .Fields(RECORDS_fld_ID)

       .CloseDown

   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

       .Save
       .CloseDown

   End With

   Set oRelation = Nothing

   oConstit.Save

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.