Private Sub EditAdjustment()  

   'This example edits the adjustment we just added, adds a note, changes the installment schedule to be four

   'installments of $15, $5, $20, and $80, and then shows our built-in UI to allow the user to re-apply the

   'payment to an installment in the new schedule.  Note that, in doing so, we lose the audit trail of how the

   'payment was distributed before editing the adjustment.

   

   Dim lPledgeId As Long

   Dim oPledge As CGift

   Dim oAdjustment As IBBAdjustment

   Dim oInstallment As CInstallment

   Dim oAdjustmentServer As CAdjustmentServer

   Dim oAdjustmentPayment As CAdjustmentPayment

   Dim oAppliedInstallment As CAppliedInstallment

   Dim oPaymentDistributionsForm As CPaymentDistributionForm

   

   Dim goSessionContext As IBBSessionContext

   Set goSessionContext = REApplication.SessionContext

   On Error GoTo eh

   

   lPledgeId = 1311

   

   Set oPledge = New CGift

   With oPledge

       .Init goSessionContext

       .Load lPledgeId

   

       Set oAdjustmentServer = New CAdjustmentServer

       With oAdjustmentServer

           .Init goSessionContext, oPledge

                       

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

           'current adjustments and writeoffs on the pledge.

           Set oAdjustment = .EditAdjustment(oPledge.Adjustments.Item(1))

           With oAdjustment

       

               'let the user set fields on the adjustment

               .Fields(ADJUSTMENT_fld_Notes) = "Oops - forgot to add the note!"

               

               'let the user specify the new installment schedule.  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_Amount) = 15

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

               End With

               

               With .Installments.Add

                   .Fields(INSTALLMENT_fld_Amount) = 5

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

               End With

               

               With .Installments.Add

                   .Fields(INSTALLMENT_fld_Amount) = 20

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

               End With

               

               With .Installments.Add

                   .Fields(INSTALLMENT_fld_Amount) = 80

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

               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, then they can simply re-issue it.

           .LoadMappingInfo

           

           'Since we've changed the installment schedule and are going to re-specify the distribution across the

           'new installments, it is easier to remove all existing applications before re-mapping.

           For Each oAdjustmentPayment In .AdjustmentPayments

               For Each oAppliedInstallment In oAdjustmentPayment.AppliedInstallments

                   oAdjustmentPayment.AppliedInstallments.Remove oAppliedInstallment

               Next oAppliedInstallment

               Set oAppliedInstallment = Nothing

           Next oAdjustmentPayment

           Set oAdjustmentPayment = Nothing

       

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

           'in the WorkInstallments collection.  This shows our built-in UI form.

           Set oPaymentDistributionsForm = New CPaymentDistributionForm

           With oPaymentDistributionsForm

               .Init goSessionContext

               Set .AdjustmentServer = oAdjustmentServer

               .ShowForm True

               .CloseDown

           End With

           Set oPaymentDistributionsForm = Nothing

       

           '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, 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.