by ALEEMUDDIN SIDDIQUI/J.S. BUSINESS SYSTEMS (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 17th December 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
ACCOUNTS AND INVENTORY
mreply = MsgBox("Save <Y/N>?..................", vbYesNo + vbQuestion, "Confirmation")
If mreply = vbYes Then 'user presses "YES" option
'initialize data object variables
Dim dbs As Database, rst As Recordset
Set dbs = OpenDatabase("c:\vb\accounts.mdb")
Set rst = dbs.OpenRecordset("gldesc", dbOpenDynaset)
'start process of saving new record
mdate = Mid(MaskEdBox1.Text, 1, 2) + "/" + Mid(MaskEdBox1.Text, 4, 2) + "/" + Mid(MaskEdBox1.Text, 7, 2)
For i = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.Row = i
rst.AddNew 'create blank row for new record
'rst!Date = CDate(mdate)
rst!refno = "PV"
rst!vno = Val(Label3.Caption)
rst!desc1 = Text1.Text
'get values from grid object
MSFlexGrid1.Col = 1
rst!acode = Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col = 2
rst!Title = Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col = 3
mamount1 = Val(MSFlexGrid1.Text)
MSFlexGrid1.Col = 4
mamount2 = Val(MSFlexGrid1.Text)
rst!amount = IIf(mamount1 > 0, mamount1, mamount2 * -1)
rst.Update 'update master transaction DataBase
Next i 'cycle table/move for next record
rst.Close 'close current table
dbs.Close 'close current DataBase
'calculate maximum voucher no.
Label3.Caption = LTrim(Str(Val(Label3.Caption) + 1))
'refresh form objects
Text1.Text = " "
Text2.Text = "C"
MSFlexGrid1.Rows = 1
MSFlexGrid1.Clear
MaskEdBox1.SelStart = 0
MaskEdBox1.SelLength = 10
MaskEdBox1.SetFocus
'end of refreshing form objects
MSFlexGrid1.Rows = 2
Command1.Enabled = False
End If
End Sub
Private Sub Command2_Click()
'calculate maximum voucher no.
Label3.Caption = LTrim(Str(Val(Label3.Caption) + 1))
'refresh form objects
Text1.Text = " "
Text2.Text = "C"
MSFlexGrid1.Rows = 1
MSFlexGrid1.Clear
MaskEdBox1.SelStart = 0
MaskEdBox1.SelLength = 10
MaskEdBox1.SetFocus
'end of refreshing form objects
MSFlexGrid1.Rows = 2
Command1.Enabled = False
End Sub
Private Sub Command3_Click()
'confirm user to exit form or NOT ?
mreply = MsgBox("Exit <Y/N>?.............", vbYesNo + vbQuestion, "Confirmation")
If mreply = vbYes Then 'user presses "YES" option
Unload Me 'exit/close form
End If 'end of confirmation
'end of confirmation of exit from FORM
End Sub
Private Sub Form_Activate()
'calculate maximum voucher no.
'initialize data object memory variables
Dim dbs As Database, rst As Recordset
Set dbs = OpenDatabase("c:\vb\accounts.mdb")
Set rst = dbs.OpenRecordset("select max(vno) as mvno from gldesc")
Label3.Caption = IIf(rst!mvno > 0, LTrim(Str(rst!mvno + 1)), 1)
MSFlexGrid1.ColWidth(1) = 1500
MSFlexGrid1.ColWidth(2) = 2300
MSFlexGrid1.ColWidth(3) = 1800
MSFlexGrid1.ColWidth(4) = 1800
MSFlexGrid1.Row = 0
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = "Account Code"
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = "Account Description"
MSFlexGrid1.Col = 3
MSFlexGrid1.Text = "Debit Amount"
MSFlexGrid1.Col = 4
MSFlexGrid1.Text = "Credit Amount"
End Sub
Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
'check to see if user pressed enter key or other than enter
If KeyAscii = 13 Then 'user presses enter key
Text1.SetFocus 'shift control another object
Command1.Enabled = True
End If 'end of checking keypressed
End Sub
Private Sub MaskEdBox2_KeyPress(KeyAscii As Integer)
'check to see if user presses enter key or NOT ?
If KeyAscii = 13 Then 'user presses enter key
'initialize data object memory variables
Dim dbs As Database, rst As Recordset
Set dbs = OpenDatabase("c:\vb\accounts.mdb")
Set rst = dbs.OpenRecordset("select title from glmast where " & " trim(acode)='" & Trim(MaskEdBox2.Text) & "'")
If rst.RecordCount() > 0 Then 'record found in recordset
Label10.Caption = rst!Title
Else 'record did not find in recordset
mreply = MsgBox("Account Code Not Found ", vbCritical, "Sorry")
Label10.Caption = " "
End If 'end of checking account code
MaskEdBox3.SetFocus
End If 'end of checking user input
End Sub
Private Sub MaskEdBox3_GotFocus()
MaskEdBox3.SelStart = 0
MaskEdBox3.SelLength = 9
End Sub
Private Sub MaskEdBox3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'user presses enter key here
Text2.SetFocus
End If 'end of keypress checking
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
'check to see if user pressed enter key or other than enter
If KeyAscii = 13 Then 'user presses enter key
MaskEdBox2.SetFocus 'shift control another object
End If 'end of checking keypressed
End Sub
Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = 1
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
'check to see if user presses enter key or OTHER ?
If KeyAscii = 13 Then 'user presses enter key
'check which key user presses
Select Case Text2.Text
Case "C" 'user presses 'C'
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 2
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = Mid(MaskEdBox2.Text, 1, 4) + "-" + Mid(MaskEdBox2.Text, 6, 4)
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = Label10.Caption
MSFlexGrid1.Col = 3
MSFlexGrid1.Text = Val(MaskEdBox3.Text)
MSFlexGrid1.Col = 4
MSFlexGrid1.Text = Val(MSFlexGrid1.Text) + Val(MaskEdBox3.Text)
mamount = MSFlexGrid1.Text
MSFlexGrid1.Text = " "
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = "6003-08"
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = "CASH IN HAND"
MSFlexGrid1.Col = 4
MSFlexGrid1.Text = mamount
MaskEdBox1.SelStart = 0
MaskEdBox1.SelLength = 10
MaskEdBox1.SetFocus
Case "E" 'user presses EXIT button
mreply = MsgBox("Exit <Y/N>?................", vbYesNo + vbQuestion, "Confirmation")
If mreply = vbYes Then 'user press "YES" option
Unload Me 'close current form
End If 'end of confirmation
Case "S" 'user presses "S" key
mreply = MsgBox("Save <Y/N>?..................", vbYesNo + vbQuestion, "Confirmation")
If mreply = vbYes Then 'user presses "YES" option
'initialize data object variables
Dim dbs As Database, rst As Recordset
Set dbs = OpenDatabase("c:\vb\accounts.mdb")
Set rst = dbs.OpenRecordset("gldesc", dbOpenDynaset)
'start process of saving new record
mdate = Mid(MaskEdBox1.Text, 1, 2) + "/" + Mid(MaskEdBox1.Text, 4, 2) + "/" + Mid(MaskEdBox1.Text, 7, 2)
For i = 1 To MSFlexGrid1.Rows - 1
MSFlexGrid1.Row = i
rst.AddNew 'create blank row for new record
'rst!Date = CDate(mdate)
rst!Date = Mid(MaskEdBox1.Text, 1, 2) + "-" + Mid(MaskEdBox1.Text, 4, 2) + "-" + Mid(MaskEdBox1.Text, 7, 2)
rst!refno = "PV"
rst!vno = Val(Label3.Caption)
rst!desc1 = Text1.Text
'get values from grid object
MSFlexGrid1.Col = 1
rst!acode = Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col = 2
rst!Title = Trim(MSFlexGrid1.Text)
MSFlexGrid1.Col = 3
mamount1 = Val(MSFlexGrid1.Text)
MSFlexGrid1.Col = 4
mamount2 = Val(MSFlexGrid1.Text)
rst!amount = IIf(mamount1 > 0, mamount1, mamount2 * -1)
rst!debit = mamount1
rst!credit = mamount2
rst.Update 'update master transaction DataBase
Next i 'cycle table/move for next record
rst.Close 'close current table
dbs.Close 'close current DataBase
'calculate maximum voucher no.
Label3.Caption = LTrim(Str(Val(Label3.Caption) + 1))
'refresh form objects
Text1.Text = " "
Text2.Text = "C"
MSFlexGrid1.Rows = 1
MSFlexGrid1.Clear
MaskEdBox1.SelStart = 0
MaskEdBox1.SelLength = 10
MaskEdBox1.SetFocus
'end of refreshing form objects
MSFlexGrid1.Rows = 2
End If 'end of saving confirmation
'end of process of saving new record
End Select
End If
End Sub