Default fields for the payment can be pulled from either the individual pledge or from multiple if more than one is specified in the form to the end-user.  The IBBPledgePayer object can be set or, in the example below, cast in order to surface DefaultPaymentFieldsFromMultiplePledges.  Matching gifts also need a decision on whether to handle in this snip or to ignore.  The below assumes defaults from Matching Gifts versus ignoring:
 
Public Sub testApplyToPledgeForm()
    Dim oGift As CGift
    Dim oForm As CApplyToPledgeForm
    Dim oMatchGift As IBBMatchingGift
    
    Dim oPledgePayer As IBBPledgePayer
    
    Dim oPledge As CGift
    
    Set oGift = New CGift
    Dim lGiftID As Long
    With oGift
        .Init REApplication.SessionContext
        '' Uncomment next line if you do not wish to handle matching gifts with this payment
        '.OverrideDefaultMGCompanies = True
        .Fields(GIFT_fld_Constit_ID) = 966 'Adjust to proper constit system id
        .Fields(GIFT_fld_Date) = Date
        .Fields(GIFT_fld_Amount) = 11
    End With
    
    Set oForm = New CApplyToPledgeForm
    With oForm
        .Init REApplication.SessionContext
        .ApplyToType = 0
        '.ApplyToType = ApplyToPledge
        
        Set .PaymentObject = oGift
        
        .ShowForm True
        
        If Not .Cancelled Then
            With oGift
                
                '' set default fields on payment from pledge(s)
                If .PledgePayer.PledgeCount = 1 Then
                    .PledgePayer.DefaultPaymentFieldsFromPledge
                Else
                    IBBPledgePayerCast(.PledgePayer).DefaultPaymentFieldsFromMultiplePledges
                End If
                
                '' Handle Matching gifts - comment out or remove if not handling matching gifts
                For Each oMatchGift In .MatchingGifts
                    oMatchGift.DefaultMGInfoFromGift
                Next oMatchGift
            
                .Validate
                .Save
            End With
        End If
        
        .Closedown
    End With
    
    'cleanup
    Set oForm = Nothing
    Set oGift = Nothing
    
End Sub


Private Function IBBPledgePayerCast(ByVal o As IBBPledgePayer) As IBBPledgePayer
    Set IBBPledgePayerCast = o
End Function
VBA/API
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.