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

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

   'oRecord              : record object being saved

   'bCancel              : set to true to cancel the save operation

   Dim oARInvoice As CARInvoice


   On Error GoTo ErrHandler


   Set oARInvoice = oRecord


   Dim oItem As CARLineItem


   If Not oARInvoice Is Nothing Then

       'bCancel = < place your custom save criteria here >


       For Each oItem In oARInvoice.LineItems


           Dim oDist As IBBDistribution


           For Each oDist In oItem.Distribution

               If oDist.Fields(BBDISTRIBUTIONS_fld_DEBITACCTNUM) Like "##-####-00" Then

                    'When looping through the transaction distribution, Debit, Credit or Interfund Debit/Credit must be specified

                   Dim oTDist As IBBTranDistribution

                   For Each oTDist In oDist.TransactionDistributions(bbTranDistType_Debit)

                       If oTDist.Fields(BBTRANSACTIONDISTRIBUTIONS_fld_TRANSACTIONCODE3) = "" Then

                           bCancel = True

                           MsgBox ("You must specify a T-Code")

                           Exit Sub

                       End If

                   Next oTDist

               End If

           Next oDist



       Next oItem

   End If


   Set oDist = Nothing

   Set oTDist = Nothing

   Set oItem = Nothing

   Set oARInvoice = Nothing


   On Error GoTo 0


   Exit Sub



   Dim sErr As String

   sErr = err.Description

   On Error GoTo 0

   '< place your custom error handling code here >

   MsgBox "Error processing ARInvoice_BeforeSave : " & sErr


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