Private Sub AddAdjustment()



   'This example starts with a $100 pledge in four $25 installments with a $20 payment against the first installment.

   'It adds an adjustment to the pledge, and changes the pledge amount to be $120, changes the fund, the installment

   'schedule to be a single installment, and re-applies thhe $20 payment to the new installment.

   

   Dim lPledgeId As Long

   Dim oPledge As CGift

   Dim oAdjustment As IBBAdjustment

   Dim oInstallment As CInstallment

   Dim oAdjustmentServer As CAdjustmentServer

   

 

   

   On Error GoTo eh

   

   lPledgeId = 1502

   

   Set oPledge = New CGift

   With oPledge

       .Init REApplication.SessionContext

       .Load lPledgeId

   

       Set oAdjustmentServer = New CAdjustmentServer

       With oAdjustmentServer

           .Init REApplication.SessionContext, oPledge

                       

           'If payments/writeoffs exist, then this statement will populate the AdjustmentPayments collection with the

           'current adjustments and writeoffs on the pledge.

           Set oAdjustment = .AddAdjustment()

           With oAdjustment

       

               'let the user set fields on the adjustment

               .Fields(ADJUSTMENT_fld_Amount) = 120

               .Fields(ADJUSTMENT_fld_Fund) = "Acquisition Fund"

       

               'let the user specify the new installment schedule - note that we default the installment schedule as

               'a copy of the existing schedule.  This is for convenience when the installment schedule is not going to

               'be changed.  In this case, since we are changing the installment schedule, it is easier to remove all

               'existing installments before adding the new installment.

               For Each oInstallment In .Installments

                   .Installments.Remove oInstallment

               Next oInstallment

               Set oInstallment = Nothing

               

               With .Installments.Add()

                   .Fields(INSTALLMENT_fld_Date) = "1/28/2000"

                   .Fields(INSTALLMENT_fld_Amount) = oAdjustment.Fields(ADJUSTMENT_fld_Amount)

               End With

           End With

       

           'at this point, we assume that the user is finished setting adjustment fields and has finished setting up the

           'new installment schedule.  This statement copies the installments in the oAdjustment.Installments collection

           'to the oAdjustmentServer.WorkInstallments collection.  This statement can be called multiple times, though,

           'so if the user decides to add another installment after this has been called, they can simply re-issue it.

           .LoadMappingInfo

       

           'at this point, the user should indicate how to distribute each AdjustmentPayment across installments in

           'the WorkInstallments collection.

           With .AdjustmentPayments.Item(1)

               With .AppliedInstallments.Add()

                   .Fields(APPLIEDINSTALLMENT_fld_InstallmentID) = oAdjustmentServer.WorkInstallments.Item(1).Fields(WORKINSTALLMENT_fld_InstallmentId)

                   'This amount must match the amount prevously applied.

                   .Fields(APPLIEDINSTALLMENT_fld_AppliedAmount) = 50

               End With

           End With

                   

           'now we can save the adjustment

           .Validate

           .Save

           .CloseDown

       End With

       Set oAdjustmentServer = Nothing

       

       .CloseDown

   End With

   Set oPledge = Nothing

   

   Exit Sub

   

eh:

   If Not oPledge Is Nothing Then

       oPledge.CloseDown

       Set oPledge = Nothing

   End If

   

   If Not oAdjustmentServer Is Nothing Then

       oAdjustmentServer.CloseDown

       Set oAdjustmentServer = Nothing

   End If

   

   MsgBox Err.Description, vbInformation



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.