Following code needs to be pasted in the MacroClass1 (overwrite existing code) in a new project created through the RE7 VBA DLL Tool:




Option Explicit



Implements IBBObjectListener





'--DECLARATIONS BEGIN--------------------------------------

Private WithEvents REApplication As REApplicationMT 'Provides access to the SessionContext



'These objects provide the BeforeSave,AfterSave, etc. events

Private WithEvents ActiveCampaign As RaisersEdgeRecord

Private WithEvents ActiveAppeal As RaisersEdgeRecord

Private WithEvents ActiveFund As RaisersEdgeRecord

Private WithEvents ActiveConstituent As RaisersEdgeRecord

Private WithEvents ActiveGift As RaisersEdgeRecord

Private WithEvents ActiveSpecialEvent As RaisersEdgeRecord

Private WithEvents ActiveJob As RaisersEdgeRecord

Private WithEvents ActiveAction As RaisersEdgeRecord

Private WithEvents ActiveMembership As RaisersEdgeRecord

Private WithEvents ActiveBatch As BatchVBARecord

Private WithEvents ActiveImport As ImportVBARecord

Private WithEvents ActiveReport As ReportsVBARecord

Private WithEvents ActiveMail As MailVBARecord



'--DECLARATIONS END--------------------------------------





'--STANDARD CONNECTION CODE BEGIN-------------------------------

Private Sub GetReObjects(Application As REApplicationMT)

   Set REApplication = Application

   

   Set ActiveCampaign = Application.ActiveRecord(vbaActiveCampaign)

   Set ActiveAppeal = Application.ActiveRecord(vbaActiveAppeal)

   Set ActiveFund = Application.ActiveRecord(vbaActiveFund)

   Set ActiveConstituent = Application.ActiveRecord(vbaActiveConstit)

   Set ActiveGift = Application.ActiveRecord(vbaActiveGift)

   Set ActiveSpecialEvent = Application.ActiveRecord(vbaActiveSpecialEvent)

   Set ActiveJob = Application.ActiveRecord(vbaActiveJob)

   Set ActiveAction = Application.ActiveRecord(vbaActiveAction)

   Set ActiveMembership = Application.ActiveRecord(vbaActiveMembership)

   

   Set ActiveBatch = Application.ActiveBatch

   Set ActiveImport = Application.ActiveImport

   Set ActiveMail = Application.ActiveMail

   Set ActiveReport = Application.ActiveReport



End Sub

Private Sub ReleaseREObjects()

   

   Set ActiveCampaign = Nothing

   Set ActiveAppeal = Nothing

   Set ActiveFund = Nothing

   Set ActiveConstituent = Nothing

   Set ActiveGift = Nothing

   Set ActiveSpecialEvent = Nothing

   Set ActiveJob = Nothing

   Set ActiveAction = Nothing

   Set ActiveMembership = Nothing

   

   Set ActiveBatch = Nothing

   Set ActiveImport = Nothing

   Set ActiveMail = Nothing

   Set ActiveReport = Nothing



   Set REApplication = Nothing



End Sub



Private Sub REApplicationMTInstance_OnConnection(ByVal Application As REApplicationMT, ByVal MTDllInst As Object, Custom() As Variant)

   'Cache application object when a user logs in

   GetReObjects Application

   CustomConnect

   

End Sub



Private Sub REApplicationMTInstance_OnDisconnection(Custom() As Variant)

   'Release all objects when a user logs out

   CustomDisconnect

   ReleaseREObjects

   

End Sub

Private Sub CustomConnect()

'TODO: Add any custom connection code here



End Sub

Private Sub CustomDisconnect()

'TODO: Add any custom tear-down code here

   RemoveListener

End Sub

'--STANDARD CONNECTION CODE END-------------------------------





'---TODO: Add your macro code below this line---------------



'This procedure will be called each time a record of the specified type is closed

Public Sub Gift_CloseRecord()

   RemoveListener

End Sub

'This procedure will be called when a record of the specified type is opened

Public Sub Gift_BeforeOpen(oRecord As Object)

'oRecord: record object being opened

   InstallListener

End Sub

Sub InstallListener()

   RemoveListener

   Dim oSC As IBBSessionContext

   Set oSC = REApplication.SessionContext

   oSC.ObjectDispatcher.AddListener Me

   Dim oFO As IBBFeatureOptions

   Set oFO = oSC

   oFO.Enable750ObjectEvents = True

End Sub

Sub RemoveListener()

   If Initialized Then

       Dim oSC As IBBSessionContext

       Set oSC = REApplication.SessionContext

       oSC.ObjectDispatcher.RemoveListener Me

   End If

End Sub





Public Property Get Session() As IBBSessionContext

   Set Session = REApplication.SessionContext

End Property



Public Property Get Initialized() As Boolean

   If Not REApplication Is Nothing Then

       If Not REApplication.SessionContext Is Nothing Then Initialized = True

   End If

End Property



Private Sub IBBObjectListener_MetaObjectEvent(ByVal lObjectEvent As BBREAPI7.bbObjectEvents, ByVal lObjectType As BBREAPI7.bbMetaObjects, ByVal oMetaObject As BBREAPI7.IBBMetaField, bCancel As Boolean)

'No code needed but the routine is needed

End Sub

Private Sub IBBObjectListener_ObjectEvent(ByVal lObjectEvent As BBREAPI7.bbObjectEvents, ByVal lObjectType As BBREAPI7.bbDataObjConstants, ByVal oDataObject As BBREAPI7.IBBDataObject, bCancel As Boolean)

'Used the BeforeDeleteCommand

   If Not Initialized Then Exit Sub

   If lObjectEvent = bbOE_ObjectBeforeDelete Then

   'Check for record type of Writeoff

       If TypeOf oDataObject Is IBBWriteOff Then

           Dim oWriteoff As IBBWriteOff

           Dim oRecord As CRecord

           Dim oSess As IBBSessionContext

           Set oWriteoff = oDataObject

           Set oSess = Session

           Set oRecord = New CRecord

           oRecord.Init oSess

           oRecord.Load 280

           MsgBox "Opened record " & oRecord.Fields(RECORDS_fld_FIRST_NAME) & " " & oRecord.Fields(RECORDS_fld_LAST_NAME)

           MsgBox "Deleting writeoff " & oWriteoff.Fields(WRITEOFF_fld_Amount) & " - " & oWriteoff.Fields(WRITEOFF_fld_Date)

           oRecord.CloseDown

           Set oRecord = Nothing

       End If

   End If

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.