Point of Sale Tutorial Part 4 – Code for adding designation and cash tend form
In previous tutorial, we created graphical user interface and database design of our project, this time we are going to code every forms to compose the components of our POS program. Let's start!.
Copy and Paste this in your adding designation form
The second group of the code is for Cash Tend form
Copy and Paste this in your adding designation form
Option Explicit
Public UserOptions As String
Private Sub cmdDelete_Click()
If UserOptions = vbNullString Then
MsgBox "Please choose a record in the record to Delete.", vbExclamation, "Warning!"
Exit Sub
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from Designation where Designation='" & UserOptions & "'", cn, adOpenKeyset, adLockPessimistic
With rs
.Delete
Call LoadListviewDesignation
.Close
End With
Set rs = Nothing
MsgBox "Record Successfully Deleted!", vbInformation, "Success Deleted!"
txtAddDesig.Text = ""
End If
UserOptions = ""
End Sub
Private Sub txtAddDesig_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub
Private Sub cmdSave_Click()
If txtAddDesig.Text = vbNullString Then
MsgBox "Please fill the text field.", vbCritical, "Error"
txtAddDesig.Text = vbNullString
Exit Sub
ElseIf IsNumeric(txtAddDesig.Text) = True Then
MsgBox "Number value is not allowed.", vbCritical, "Error"
txtAddDesig.Text = vbNullString
Exit Sub
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from Designation", cn, adOpenKeyset, adLockPessimistic
With rs
.AddNew
.Fields("Designation") = txtAddDesig.Text
.Update
.Close
End With
Set rs = Nothing
MsgBox "Record Successfully Saved!", vbInformation, "Success Saved!"
Call LoadListviewDesignation
txtAddDesig.Text = vbNullString
txtAddDesig.SetFocus
End If
End Sub
Private Sub Form_Load()
Module2.Connect
Call Module2.LoadListviewDesignation
End Sub
Private Sub btnDelete_Click()
If UserOptions = vbNullString Then
MsgBox "Please choose a record in the record to Delete.", vbExclamation, "Warning!"
Else
Set rs = New ADODB.Recordset
rs.Open "Select * from Designation where Designation='" & UserOptions & "'", cn, adOpenKeyset, adLockPessimistic
With rs
.Delete
.Close
End With
Set rs = Nothing
MsgBox "Record Successfully Deleted!", vbInformation, "Success Deleted!"
txtAddDesig.Text = ""
End If
End Sub
Private Sub lvDesignation_Click()
On Error Resume Next
UserOptions = lvDesignation.SelectedItem.SubItems(1)
txtAddDesig.Text = lvDesignation.SelectedItem.SubItems(1)
End Sub
Private Sub txtAddDesig_LostFocus()
txtAddDesig.Text = StrConv(txtAddDesig.Text, vbProperCase)
End Sub
The second group of the code is for Cash Tend form
Option ExplicitThe next tutorial is the login and look up forms!
Public CASH_TEND As Double
Public CASH_CHANGE As Double
Private Sub Form_Activate()
On Error Resume Next
txtCashTend.SetFocus
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Unload Me
End If
End Sub
Private Sub Form_Load()
On Error GoTo ERR_LOAD
Exit Sub
ERR_LOAD:
MsgBox "Error Number:" & Err.Number & vbNewLine & "Description:" & Err.Description, vbExclamation, "Error Loading"
End Sub
Private Sub txtCashTend_Change()
txtCashTend.Text = Format(txtCashTend.Text, "###,###,##0.00")
End Sub
Private Sub txtCashTend_GotFocus()
Highlight txtCashTend
End Sub
Private Sub txtCashTend_KeyPress(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = 13 Then
txtCashTend.Text = Format(txtCashTend.Text, "###,###,##0.00")
CASH_TEND = txtCashTend.Text
CASH_CHANGE = CASH_TEND - frmPOS.lblTotalAmount
With frmPOS
.lblCashTend.Caption = txtCashTend.Text
.lblChange.Caption = Format(CASH_CHANGE, "###,###,###.00")
End With
Unload Me
End If
End Sub
Private Sub txtCashTend_LostFocus()
txtCashTend.Text = Format(txtCashTend.Text, "###,###,##0.00")
End Sub
Public Sub Highlight(ByRef srcText)
On Error Resume Next
With srcText
.SelStart = 0
.SelLength = Len(srcText.Text)
End With
End Sub
Point of Sale Tutorial Part 4 – Code for adding designation and cash tend form
Reviewed by code-dev
on
11:13 AM
Rating:
No comments: