The guts of the code is as follows :
- Code: Select all
Private Function CreateCashBookBatch(ByRef NewBatchNo As String) As Boolean
Dim lNewKey As String
Dim SampleBankAccountID As String
Dim SampleDebtorID As String
On Error GoTo ErrorHandler
CreateCashBookBatch = True
SampleBankAccountID = "00000000O0000000006P" ' This is the "Cash At Bank NSW" ledger in Demo data
SampleDebtorID = "0000000061000000001V" ' This is debtor 1001 in demo data
If CreateCashBookBatch = True Then
Set CashBook = New clsCashBook
Set CashBook.Database = Database
Set CashBook.JiwaCommLib = JiwaCommLib
Set CashBook.JLib = JLib
Set CashBook.SystemProfile = SystemProfile
End If
If CreateCashBookBatch = True Then
If CashBook.Setup = e_CashbookReturnCodeFailure Then
CreateCashBookBatch = False
ErrorString = CashBook.ErrorString
ErrorModule = CashBook.ErrorModule
End If
End If
If CreateCashBookBatch = True Then
If CashBook.PrepareNewRecord = e_CashbookReturnCodeFailure Then
CreateCashBookBatch = False
ErrorString = CashBook.ErrorString
ErrorModule = CashBook.ErrorModule
End If
End If
If CreateCashBookBatch = True Then
CashBook.BankLedgerID = SampleBankAccountID
CashBook.BatchDate = Now
CashBook.CashBookType = e_CashBookReceipt
CashBook.Description = "Imported Batch"
End If
If CreateCashBookBatch = True Then
'Add a new debtor transaction
If CashBook.AddNewTransaction(e_CashBookTransactionTypeDebtorTransaction, SampleDebtorID, lNewKey) = e_CashbookReturnCodeFailure Then
CreateCashBookBatch = False
ErrorString = CashBook.ErrorString
ErrorModule = CashBook.ErrorModule
Else
CashBook.CashBookTransactions(lNewKey).RemitNo = "test"
CashBook.CashBookTransactions(lNewKey).HomeAmount = 100
CashBook.CashBookTransactions(lNewKey).Remark = "remark"
CashBook.CashBookTransactions(lNewKey).Reference = "reference"
CashBook.CashBookTransactions(lNewKey).TranDate = Now
End If
End If
If CreateCashBookBatch = True Then
' CashBook.Activated = True ' Uncomment this line if you want the batch activated on save
If CashBook.SaveRecord = e_CashbookReturnCodeFailure Then
CreateCashBookBatch = False
ErrorString = CashBook.ErrorString
ErrorModule = CashBook.ErrorModule
Else
NewBatchNo = CashBook.BatchNo
End If
End If
On Error GoTo 0
Exit Function
ErrorHandler:
CreateCashBookBatch = False
ErrorString = Err.Description
ErrorModule = "Form1.CreateCashBookBatch"
Resume Next
End Function