Private Sub AddMembership(oRecord As CRecord)
    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

    Set oCodeTableServer = New CCodeTablesServer
    oCodeTableServer.Init REApplication.SessionContext

    Set oConstit = oRecord

    Select Case oConstit.Fields(RECORDS_fld_KEY_INDICATOR)
        'Checks to see if Org or Individual
        Case bbki_ORG
        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
            Next oCat
            Set oCat = Nothing

            Set oCats = Nothing

            'Assign membership Information
            .Fields(MEMBERSHIPTRANSACTION_fld_Dues) = 100
            .Fields(MEMBERSHIPTRANSACTION_fld_ActivityDate) = "8/1/2002"
             Fields(MEMBERSHIPTRANSACTION_fld_Expires_On) = "8/31/2003"

        End With

        'Save the constituent and then the membership
        'Clean up
        Set oMember = Nothing
    End Select
    'Clean up
    Set oConstit = Nothing

    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.