In VBA, the following code needs to be placed in the Membership_BeforeSave Event:

Public Sub Membership_BeforeSave(oRecord As Object, bCancel As Boolean)
    'oRecord              : record object being saved
    'bCancel              : set to true to cancel the save operation

    Dim oMembership As CMembership
   
    On Error GoTo ErrHandler
   
    Set oMembership = oRecord
   
    If Not oMembership Is Nothing Then
        'bCancel = < place your custom save criteria here >
       
        If oMembership.Transactions.Item(1).Benefits.Count = 0 Then
            With oMembership.Transactions.Item(1).Benefits.Add
                .Fields(BENEFIT_fld_Benefit) = "Calendar"
                .Fields(BENEFIT_fld_Count) = 1
                .Fields(BENEFIT_fld_UnitCost) = 5
            End With
        Else: MsgBox "Nope, try again"
        End If
       
    End If
   
    Set oMembership = Nothing
   
    On Error GoTo 0
   
    Exit Sub
   
ErrHandler:
    Dim sErr As String
    sErr = Err.Description
    On Error GoTo 0
    '< place your custom error handling code here >
    MsgBox "Error processing Membership_BeforeSave : " & sErr
   
    Set oMembership = Nothing
    bCancel = False
   
    Exit Sub

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. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.