Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

VB Banking System

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 2 posts
I 'm obviously new to programming and I need help. I'm trying to design a banking system in VB. The withdrawal mechanism is giving me trouble.
My requirements are:
The systen should check your name and if the account name exists and is correct, proceed to check that your account number and PIN number are correct and match.
Once this is done and no fields are blank, the system should then allow the person to withdraw money.
The snag comes when I try to ensure that a customer cannot withdraw more money than they have.
With my currrent code if I add the "If withdrawal > oldbalance Then MsgBox a" bit then it messes up the if statements and i dont get the error message for wrong PIN or Account number which is in the Else if statement further on.
But if I remove the wrong PIN or Account number code I get the error message saying there are insuffcient funds but the system still withdraws leaving a negative account balance.
If I remove the checking code, the validation systen works great but gives me an inaccurate receipt and alows me to withdraw money from nonexistent accounts! :whistling:

Here is my code:

'the button which sets the ball rolling
Private Sub Cmdsave_Click()

Dim mode As String
Dim a As String

TxtDate.Text = Date

'the error message for attempting to overdraw the account
a = " The withdrawal amount is greater than the Account Balance. Please enter a lower figure or see the Bank manager for Overdraft Facilities"

'checks if the withdrawal is in cash or cheque
If ChkCash.value = 1 Then
mode = "Cash"
End If
If ChkCheque.value = 1 Then
mode = "Cheque"
End If
Txtmode.Text = mode

'validation code to ensure no fields are left blank.
If TxtName.Text = "" Then
MsgBox "Please enter Account Details."
cancel = True

If TxtWAmt.Text = "" Then
MsgBox "Please Enter the amount to be withdrawn"
cancel = True

If Txtmode.Text = "" Then
MsgBox "Please select a mode of payment"
cancel = True

'code to check whether the account name exists in the system.
Adodc2.Recordset.Find "Name='" & TxtName.Text & "'"
If Adodc2.Recordset.EOF = True Then
MsgBox "Invalid Account Holder"

'code to check whether PIN & Account numbers are correct
If TxtAccountNo.Text = Adodc2.Recordset!AccountNo And TxtPIN.Text = Adodc2.Recordset!PINNo Then

Dim oldbalance As Double
Dim withdrawal As Double
Dim newbalance As Double

oldbalance = TxtOldAcBal.Text
withdrawal = TxtWAmt.Text
newbalance = oldbalance - withdrawal
txtNewAcBal.Text = newbalance

'validation code to prevent withdrawing more than the current account balance
If withdrawal > oldbalance Then
MsgBox a
cancel = True


'if the above is fine, then record the withdrawal in the withdrawal records
MsgBox "Withdrawal Recorded"

' then change the account balance to the new balance
CmdSlip.Enabled = True

'Reset the withdrawal panel

'Code to give error message if the wrong PIN or Account number is put in.

MsgBox "Invalid Account Number or PIN Number, try again!"

End If
End If
End If
End If
End If
End If
End If
End Sub

'the code that generates the reciept
Private Sub CmdSlip_Click()
TxtSliph.Visible = True

TxtSlipd.Visible = True
TxtSliph.Text = " KENYA COMMERCIAL BANK " & vbCrLf & _
vbCrLf & _
TxtSlipd.Text = "Date: " & Date & " Time: " & Time & vbCrLf & _
vbCrLf & _
"Account Number: " & TxtAccountNo.Text & vbCrLf & _
vbCrLf & _
"Amount Withdrawn: " & TxtWAmt.Text

End Sub

Private Sub Form_Load()


End Sub
  • 0





  • Member
  • PipPip
  • 74 posts
Your code is very hard to read. It would help if you put it in code tags.

Check to see what the value of oldbalance and withdrawal is after you assign them the values from the text boxes. You should actually be doing an explicit conversion from text to double when you assign the values from the text boxes to the double variables.

Also I'm not sure how you actually have it structured in your code but if you actually do have all of those elses with ifs inside the elses it would be much more read readable and a bit more efficient if you changed the elses to elseif.
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP