here's the code. i will post the combo box code on 12 May 2008. take note
that me.[account number] and me.[balance] belongs to that of the wrong record.
--- code starts here ---
private sub MyButton_OnClick
'do not allow blank or invalid data.
If (IsDataComplete = False) Then
GoTo Exit_commandDepositWithdraw_Click
End If
If (Me.textboxTransactionAmount.Visible = False) Then 'make sure the
textboxTransactionAmount control is visible to ensure user has keyed in the
transaction amount.
MsgBox "Please make sure the transaction amount is entered.",
vbOKOnly, MSGBOX_TITLE
GoTo Exit_commandDepositWithdraw_Click
End If
'do not allow cash transaction and non-cash (e.g. cheque) transaction to
be made in the same transaction.
'a cash transaction will require 1 form to be filled and a non-cash
transaction will require another form to be filled.
Select Case UCase(Me.textboxTransactionAction)
Case Is = "WITHDRAWAL"
'do not allow withdrawal that exceeds balance.
If ((Me.textboxTransactionAmount) > Me.[Bank Balance]) Then
MsgBox "The withdrawal amount of " +
Format(Me.textboxTransactionAmount, "$#,###.00") + " is greater than the
available balance of " + Format(Me.[Bank Balance], "$#,###.00") + ". The
withdrawal cannot be made.", vbOKOnly, MSGBOX_TITLE
GoTo Exit_commandDepositWithdraw_Click
End If
End Select
'get user's confirmation on the transaction.
If (MsgBox("You have chosen to make a " &
UCase(Me.textboxTransactionAction) & ". Is this correct?", vbYesNo,
MSGBOX_TITLE) = vbNo) Then 'UCase(Me.textboxTransactionAction) is either
"DEPOSIT" or "WITHDRAWAL".
GoTo Exit_commandDepositWithdraw_Click
End If
DoCmd.OpenReport "report TransactionRecord" 'print a record of the
deposit/withdrawal transaction.
'update transactions history table.
Dim cnn1 As ADODB.Connection
Dim rstTransactionsHistory As ADODB.Recordset
Dim rstCashInHand As ADODB.Recordset
Dim strTransactionReference As String
' open a connection.
Set cnn1 = New ADODB.Connection
cnn1.Open DATABASE_CONNECTION_STRING
'Set cnn1 = Application.CurrentProject.Connection
' open transactions history table.
Set rstTransactionsHistory = New ADODB.Recordset
rstTransactionsHistory.CursorType = adOpenKeyset
rstTransactionsHistory.LockType = adLockOptimistic
rstTransactionsHistory.Open "TransactionHistory", cnn1, , , adCmdTable
' open cash in hand table.
Set rstCashInHand = New ADODB.Recordset
rstCashInHand.CursorType = adOpenKeyset
rstCashInHand.LockType = adLockOptimistic
rstCashInHand.Open "CashInHand", cnn1, , , adCmdTable
'update transactions history table.
rstTransactionsHistory.AddNew
rstTransactionsHistory![Account Number] = Me.[Account Number]
rstTransactionsHistory![Date] = Me.textboxDate
rstTransactionsHistory![Time] = getTimeIn24HoursFormat(Time)
Select Case UCase(Me.textboxTransactionAction)
Case Is = "DEPOSIT"
rstTransactionsHistory![Amount] = Me.textboxTransactionAmount
Case Is = "WITHDRAWAL"
rstTransactionsHistory![Amount] = (Me.textboxTransactionAmount) * -1
'store number as negative number for withdrawal.
End Select
rstTransactionsHistory![Transaction Reference] =
Me.textboxTransactionReference
rstTransactionsHistory![Transaction Code] = Me.comboSelectTransactionType
rstTransactionsHistory![Remarks] = Me.textboxRemarks
Select Case Me.comboSelectTransactionMode
Case Is = "CASH"
rstTransactionsHistory![Transaction Mode] = "C" 'cash transaction.
Case Is = "NON CASH"
rstTransactionsHistory![Transaction Mode] = "Q" 'non cash transaction.
End Select
rstTransactionsHistory.Update
'update cash in hand table
If (Me.comboSelectTransactionMode = "CASH") Then 'update cash in hand
only for cash transaction.
Select Case UCase(Me.textboxTransactionAction)
Case Is = "DEPOSIT"
'add amount to cash in hand balance.
rstCashInHand![Cash Balance] = rstCashInHand![Cash Balance] +
Me.textboxTransactionAmount
Case Is = "WITHDRAWAL"
'deduct amount from cash in hand balance.
rstCashInHand![Cash Balance] = rstCashInHand![Cash Balance] -
Me.textboxTransactionAmount
End Select
End If
rstCashInHand.Update
rstTransactionsHistory.Close
Set rstTransactionsHistory = Nothing
rstCashInHand.Close
Set rstCashInHand = Nothing
cnn1.Close
Set cnn1 = Nothing
'update member's members' bank balance.
Select Case UCase(Me.textboxTransactionAction)
Case Is = "DEPOSIT"
'add amount to member's balance.
Me.[Bank Balance] = Me.[Bank Balance] + Me.textboxTransactionAmount
Case Is = "WITHDRAWAL"
'deduct amount from member's balance.
Me.[Bank Balance] = Me.[Bank Balance] - Me.textboxTransactionAmount
End Select
Me.Requery 'update display in form and [Bank Balance] field in members
table.
If (Me.comboSelectTransactionType.Column(4) = True) Then 'check if
transaction type auto increment transaction number.
UpdateLastUsedTransactionNumber 'update table with last used
transaction number.
End If
'remove amount of previous transaction so user don't accidentally
deposit/withdraw amount more than once by clicking the deposit/withdrawal
button.
Me.textboxTransactionAmount = 0
'clear data of current transaction to prepare for next new transaction.
This will prevent old data from being saved accidentally.
Me.comboSelectAMember = ""
Me.textboxAccountNumber = ""
Me.textboxBankBalance = ""
Me.textboxName = ""
Me.textboxMemberRemarks = ""
Me.comboSelectTransactionType = ""
Me.textboxTransactionAction = ""
Me.textboxTransactionReference = ""
Me.textboxRemarks = ""
Me.commandDepositWithdraw.Caption = "Deposit/Withdrawal"
Me.commandDepositWithdraw.Enabled = False
Me.labelAmountToDepositWithdraw.Visible = False
Me.textboxTransactionAmount.Visible = False
Me.comboSelectTransactionMode = ""
end sub
--- code ends here ---