'Creating a new batch:
Private Sub CreateBatch()
  
   Dim oBatchAPI As CBatchAPI
   Dim oBatchFields As CBatchFields
  
   Set oBatchAPI = New CBatchAPI
   With oBatchAPI
       .Init REApplication.SessionContext 'moSC
  
       'Add batch fields
       Set oBatchFields = .BatchFields
       With oBatchFields
           SetupBatchField .Add(), GIFT_fld_Constit_ID
           SetupBatchField .Add(), GIFT_fld_ID
           SetupBatchField .Add(), GIFT_fld_Amount
           SetupBatchField .Add(), GIFT_fld_Fund
           SetupBatchField .Add(), GIFT_fld_Date
           SetupBatchField .Add(), GIFT_fld_Post_Date
           SetupBatchField .Add(), GIFT_fld_Post_Status
       End With
       Set oBatchFields = Nothing
      
       .Save
       .CloseDown
   End With   
   Set oBatchAPI = Nothing
  
End Function

'Linking the Gift object to the batch fields:
Private Sub SetupBatchField(ByVal oBatchField As CBatchField, ByVal lGiftField As EGiftFields)
  
   With oBatchField
       .Fields(BatchField_fld_MetaObjectId) = bbmoGIFT
       .Fields(BatchField_fld_FieldNumber) = lGiftField
   End With
  
End Sub

'Adding Gifts to a Batch:
Private Sub AddGiftData(ByVal lBatchID As Long)
  
   Dim oBatchAPI As CBatchAPI
   Dim oTempRecords As CTempRecords
   Dim lCntr As Long
  
   Set oBatchAPI = New CBatchAPI
   With oBatchAPI
       .Init moSC
       .Load lBatchID
       Set oTempRecords = .TempRecords
  
       'Add gifts with differing amounts as an example
       For lCntr = 1 To 10
           AddSingleGift oTempRecords.Add(), CCur(CStr(lCntr))
       Next lCntr
  
       oTempRecords.Save   
       Set oTempRecords = Nothing
       .CloseDown
   End With
   Set oBatchAPI = Nothing
  
End Sub

'Adding Gift data:
Private Sub AddSingleGift(ByVal oTempRecord As CTempRecord, ByVal curAmount As Currency)
   Dim lAttID As Long
   Dim oServices As REServices
   Dim oATS As CAttributeTypeServer
 
   Set oServices = New REServices
   oServices.Init REApplication.SessionContext

   'Get the ID of the attribute that will be added - this example uses a boolean attribute type
   Set oATS = oServices.CreateServiceObject(bbsoAttributeTypeServer)
   oATS.Init REApplication.SessionContext
   lAttID = oATS.GetAttributeTypeID("Y/N Test Attribute", bbAttributeRecordType_GIFT)
 
   Set oATS = Nothing
   oServices.CloseDown
   Set oServices = Nothing  

  
   Dim oGift As CGift
   Set oGift = New CGift
   With oGift
       .Init moSC
      
       If moRecordFinder.Search("Mark Adamson") Then
           .Fields(GIFT_fld_Constit_ID) = moRecordFinder.RecordId
       End If
      
       .Fields(GIFT_fld_Amount) = curAmount
       .Fields(GIFT_fld_ID) = "ABC123"
    

       'Set first gift Attribute column value to be True=YES
       With oGift.Attributes.Add
            .Fields(Attribute_fld_ATTRIBUTETYPES_ID) = lAttID
            .Fields(Attribute_fld_VALUE) = -1
            .Fields(Attribute_fld_COMMENTS) = "Test attribute setting"
        End With
      
       If UCase$(moServices.GetUserPref(USER_fld_FUNDFORMAT)) = "FUND ID" Then
           .Fields(GIFT_fld_Fund) = "GARDEN"
       Else
           .Fields(GIFT_fld_Fund) = "Botanical Garden Fund"
       End If
      
       Set oTempRecord.DataObject = oGift
      
       .CloseDown
   End With
   Set oGift = Nothing
  
End Sub

'Committing a Batch:
Private Sub AddGiftData(ByVal lBatchID As Long)
  
   Dim oBatchAPI As CBatchAPI
   Set oBatchAPI = New CBatchAPI
   With oBatchAPI
       .Init moSC
       .Load lBatchID
       'Commit with the default posting options, but show the options form to allow changes
       .CommitBatch Nothing, True, Nothing, True
       .CloseDown
   End With
   Set oBatchAPI = 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.