Private Sub MemberGiftPay()

   Dim oMember As CMembership
   Dim oConstit As CRecord
   Dim lProgID As Long
   Dim lCatID As Long
   Dim oCat As CMemCat
   Dim oCats As CMemCats
   Dim oCodeTableServer As CCodeTablesServer
   
   Dim ogift As CGift
   Set ogift = New CGift
   ogift.Init REApplication.SessionContext
   
   
   Set oConstit = New CRecord
   oConstit.Init REApplication.SessionContext
   
   oConstit.Load 274
   
   'Create a gift to link to the membership
   With ogift
       .Fields(GIFT_fld_Amount) = 100
       .Fields(GIFT_fld_Date) = "8/1/2005"
       .Fields(GIFT_fld_Fund) = "2005 Membership Fund"
       .Fields(GIFT_fld_Constit_ID) = oConstit.Fields(RECORDS_fld_ID)
       .Save
   End With
 
   'Save the giftID to a variable
   Dim lGID As Long
   lGID = ogift.Fields(GIFT_fld_ID)
  
   ogift.Closedown
   Set ogift = Nothing
   
   Set oCodeTableServer = New CCodeTablesServer
   oCodeTableServer.Init REApplication.SessionContext


   Select Case oConstit.Fields(RECORDS_fld_KEY_INDICATOR)
       'Checks to see if Org or Individual
       Case bbki_INDIVIDUAL
      
       Set oMember = New CMembership
       oMember.Init REApplication.SessionContext

       'Link the Membership to the constituent
       oMember.Fields(MEMBERSHIP_fld_Constit_ID) = oConstit.Fields(RECORDS_fld_ID)

       With oMember.Transactions.Add
           'Get the table entry ID for the Program and Category
           'This assumes that there is a Program named Business Level and
           'a category named Corporate within the Memberships
           lProgID = oCodeTableServer.GetTableEntryID("Business Level", tbnumMembershipPrograms)
           lCatID = oCodeTableServer.GetTableEntryID("Corporate", tbnumMembershipCategories)

           
           'Assign the Program
           .Fields(MEMBERSHIPTRANSACTION_fld_Program) = "Business Level"

           Set oCats = New CMemCats
           oCats.Init REApplication.SessionContext


           'Make sure the Program fits in the Cagegory
           For Each oCat In oCats
               If (lProgID = oCodeTableServer.GetTableEntryID(oCat.Fields(MemCat_fld_ProgramID), tbnumMembershipPrograms)) _
               And (lCatID = oCodeTableServer.GetTableEntryID(oCat.Fields(MemCat_fld_CategoryID), tbnumMembershipCategories)) Then
                       .Fields(MEMBERSHIPTRANSACTION_fld_Category) = val(oCat.Fields(MemCat_fld_MembershipCategoryID))
                       Exit For
               End If
               oCat.Closedown
           Next oCat
           Set oCat = Nothing

           oCats.Closedown
           Set oCats = Nothing


           'Assign membership information
           .Fields(MEMBERSHIPTRANSACTION_fld_Dues) = 100
           .Fields(MEMBERSHIPTRANSACTION_fld_ActivityDate) = "8/1/2005"
           .Fields(MEMBERSHIPTRANSACTION_fld_Expires_On) = "8/31/2006"
          

           'Link the gift to the Membership and apply the amount
           With .Gifts.Add
               .Fields(TRANSACTIONGIFT_fld_GiftID) = lGID
               .Fields(TRANSACTIONGIFT_fld_AppliedAmount) = 100
           End With

       End With

       'Save the constituent and then the membership
       oConstit.Save
       oMember.Save

       'Clean up
       oMember.Closedown
       Set oMember = Nothing
   
   End Select

   'Clean up
   Set oConstit = Nothing
   oCodeTableServer.Closedown
   Set oCodeTableServer = 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. 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.