Private Sub AddAdjustment_Payment()

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

   'adjusts the $20 payment on the first installment, and changes the amount to $25, changes the fund, and changes the

   'installment being paid to be the third installment.

   Dim lPledgeId As Long

   Dim lPaymentId As Long

   Dim oPledge As CGift

   Dim oPayment As CGift

   Dim oAdjustment As IBBAdjustment

   Dim oAdjustmentServer As CAdjustmentServer


   On Error GoTo eh


   lPledgeId = 355

   lPaymentId = 356


   Set oPledge = New CGift

   With oPledge

       .Init goSessionContext

       .Load lPledgeId


       Set oPayment = New CGift

       With oPayment

           .Init goSessionContext

           .Load lPaymentId


           Set oAdjustmentServer = New CAdjustmentServer

           With oAdjustmentServer

               .Init goSessionContext, oPayment


               Set oAdjustment = .AddAdjustment()

               With oAdjustment

                   'let the user set fields on the adjustment

                   .Fields(ADJUSTMENT_fld_Amount) = 25

                   .Fields(ADJUSTMENT_fld_Fund) = "Acquisition Fund"

                   .Fields(ADJUSTMENT_fld_Reason) = "Data entry error"


                   'Note that the PledgePayer on an adjustment for a payment automatically gets loaded with the

                   'applications for the payment being adjusted.  This is provided both as a convenience for the

                   'cases where the payment amount and payment applications are not going to be changed by the

                   'adjustment, as well as a method of validation in case the amount changes but is not re-distributed

                   'across installments.  Note that we call RemovePledge to first remove the existing applications,

                   'since in this example we are changing the installment being paid (we could also use

                   'RemoveInstallment method if the InstallmentId were known).

                   With .PledgePayer

                       .RemovePledge lPledgeId

                       .ApplyToInstallment oPledge.Installments.Item(3), 25

                   End With

               End With


               'now we can save the adjustment




           End With

           Set oAdjustmentServer = Nothing



       End With

       Set oPayment = Nothing



   End With

   Set oPledge = Nothing


   Exit Sub



   If Not oPayment Is Nothing Then


       Set oPayment = Nothing

   End If


   If Not oPledge Is Nothing Then


       Set oPledge = Nothing

   End If


   If Not oAdjustmentServer Is Nothing Then


       Set oAdjustmentServer = Nothing

   End If


   MsgBox Err.Description, vbInformation, goSessionContext.MsgBoxCaption

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.