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

'and will create a new TextStream



Public Sub Constituent_BeforeOpen(oRecord As Object)

   'oRecord              : record object being opened



       Dim oConstituent As CRecord

       Set oConstituent = oRecord



       Dim oTxtStreams As CDBTextStreams

       Set oTxtStreams = New CDBTextStreams

       oTxtStreams.Init REApplication.SessionContext

       'Open a Stream, if it does not exist it will be created

       With oTxtStreams.OpenStream("Test")



        'write to the stream

           .WriteTextLine oConstituent.Fields(RECORDS_fld_FULL_NAME) & " "

& Now & vbCr



        End With





        oTxtStreams.CloseDown

         Set oTxtStreams = Nothing



End Sub



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

saved and will pull the Text Stream out



Public Sub Constituent_BeforeSave(oRecord As Object, bCancel As Boolean)

   'oRecord              : record object being saved

   'bCancel              : set to true to cancel the save operation



   Dim oConstituent As CRecord



   On Error GoTo ErrHandler



   Set oConstituent = oRecord



   If Not oConstituent Is Nothing Then



   Dim oTxtStreams As CDBTextStreams

   Set oTxtStreams = New CDBTextStreams

   oTxtStreams.Init REApplication.SessionContext



   With oTxtStreams.OpenStream("Test")

   'Show the contents of the stream

       MsgBox .ReadAll

   End With





   End If



   Set oConstituent = 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 Constituent_BeforeSave : " & sErr



   Set oConstituent = 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. 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.