0% found this document useful (0 votes)
82 views

Payroll Application: Call Clearfields

This document contains code for a student information system application that uses ADO to connect to a database and perform CRUD operations on student records. It includes code to open a connection, execute queries to select, insert, update and delete student records, and code to populate and clear form fields to view, add or edit individual student details. Navigation buttons allow moving between records and functions are included to calculate and display total marks, average, class and result on lost focus events.

Uploaded by

praburaj619
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Payroll Application: Call Clearfields

This document contains code for a student information system application that uses ADO to connect to a database and perform CRUD operations on student records. It includes code to open a connection, execute queries to select, insert, update and delete student records, and code to populate and clear form fields to view, add or edit individual student details. Navigation buttons allow moving between records and functions are included to calculate and display total marks, average, class and result on lost focus events.

Uploaded by

praburaj619
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 33

Payroll Application

Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott; Password=tiger; Data Source=Payroll;Persist Security Info=False" Call SelectQuery End Sub Private Sub Form_Activate() txtEmpId = ""
Call ClearFields

txtEmpId.SetFocus End Sub Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Payroll" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() 'txtEmpId = "" txtEmpName = "" txtDesignation = "" txtDoj = "" txtBasic = "" txtDA = "" txtHRA = "" txtCCA = "" txtPF = "" txtTax = "" txtLoan = "" txtGross = "" txtNet = "" txtEmpId.SetFocus End Sub

Private Sub cmdClose_Click() txtEmpId = "" Call ClearFields Me.Hide End Sub Private Sub cmdAdd_Click() txtEmpId = "" Call ClearFields If adoRecordset.EOF then txtEmpId=1 Else adoRecordset.MoveLast txtEmpId= val(adoRecordset![Empid]) +1 End If txtEmpName.SetFocus End Sub Private Sub cmdSave_Click() If txtEmpId = "" Then MsgBox "Enter the Employee Id", vbInformation txtEmpId.SetFocus Exit Sub End If If txtEmpName = "" Then MsgBox "Enter the Employee Name", vbInformation txtEmpName.SetFocus Exit Sub End If If txtDesignation = "" Then MsgBox "Enter the Employee Designation", vbInformation txtDesignation.SetFocus Exit Sub End If If txtBasic = "" Then MsgBox "Enter the Basic Pay", vbInformation txtBasic.SetFocus Exit Sub End If Call DeleteQuery

Call SelectQuery adoRecordset.AddNew adoRecordset![Empid] = txtEmpId adoRecordset![Empname] = txtEmpName adoRecordset![Designation] = txtDesignation adoRecordset![doj] = txtDoj adoRecordset![basic] = txtBasic adoRecordset![da] = txtDA adoRecordset![hra] = txtHRA adoRecordset![cca] = txtCCA adoRecordset![pf] = txtPF adoRecordset![tax] = txtTax adoRecordset![loan] = txtLoan adoRecordset![gross] = txtGross adoRecordset![net] = txtNet adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery: txtEmpId = "": Call ClearFields End Sub Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from Payroll where Empid='" & txtEmpId & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst Call DisplayRecord MsgBox "First Record" End If End Sub

Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast Call DisplayRecord MsgBox "Last Record" End If End Sub Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord End If End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub Private Sub DisplayRecord() txtEmpId = adoRecordset![Empid] txtEmpName = adoRecordset![Empname] txtDesignation = adoRecordset![Designation] txtDoj = Format(adoRecordset![doj], "dd-mmm-yyyy") txtBasic = adoRecordset![basic] txtDA = adoRecordset![da] txtHRA = adoRecordset![hra] txtCCA = adoRecordset![cca]: txtPF = adoRecordset![pf]:

txtTax = adoRecordset![tax]: txtLoan = adoRecordset![loan]: txtGross = adoRecordset![gross]: txtNet = adoRecordset![net] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery Call CommitQuery MsgBox "Record Deleted", vbInformation txtEmpId = "" Call ClearFields End If End Sub Private Sub txtBasic_LostFocus() txtDA = Val(txtBasic) * 25 / 100 txtHRA = Val(txtBasic) * 30 / 100 txtCCA = Val(txtBasic) * 15 / 100 txtPF = Val(txtBasic) * 12.5 / 100 txtTax = Val(txtBasic) * 10 / 100 txtLoan.SetFocus End Sub Private Sub txtLoan_LostFocus() txtGross = Val(txtBasic) + Val(txtDA) + Val(txtHRA) + Val(txtCCA) txtNet = Val(txtGross) - Val(txtPF) + Val(txtTax) + Val(txtLoan) End Sub

MarkSheet Application
Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott; Password=tiger;Data Source=MarkSheet;Persist Security Info=False" Call SelectQuery End Sub Private Sub Form_Activate() txtRno = "" Call ClearFields txtRno.SetFocus End Sub Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Student" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() txtRegno = "" txtSname = "" txtDbms = "" txtVB = "" txtJava = "" txtRMT = "" txtVBlab = "" txtaverage = "" txtTotal = "" txtClass = "" txtResult = "" txtRno.SetFocus End Sub

Private Sub cmdClose_Click() txtRno = "" Call ClearFields Me.Hide End Sub Private Sub cmdAdd_Click() txtRno = "" Call ClearFields If adoRecordset.EOF then txtRno=1 Else adoRecordset.MoveLast txtRno= val(adoRecordset![Rno]) +1 End If txtEmpName.SetFocus End Sub Private Sub cmdSave_Click() If txtRno = "" Then MsgBox "Enter the Roll number", vbInformation txtRno.SetFocus Exit Sub End If If txtRegno = "" Then MsgBox "Enter the Register number", vbInformation txtRegno.SetFocus Exit Sub End If If txtSname = "" Then MsgBox "Enter the Student Name", vbInformation txtSname.SetFocus Exit Sub End If If txtDbms = "" Then MsgBox "Enter the Dbms Mark", vbInformation txtDbms.SetFocus Exit Sub End If If txtVB = "" Then MsgBox "Enter the VB Mark", vbInformation txtVB.SetFocus Exit Sub

End If If txtJava = "" Then MsgBox "Enter the Java Mark", vbInformation txtJava.SetFocus Exit Sub End If If txtRMT = "" Then MsgBox "Enter the Rmt Mark", vbInformation txtRMT.SetFocus Exit Sub End If If txtVBlab = "" Then MsgBox "Enter the Vb-Lab Mark", vbInformation txtVBlab.SetFocus Exit Sub End If Call DeleteQuery Call SelectQuery adoRecordset.AddNew adoRecordset![Rno] = txtRno adoRecordset![Regno] = txtRegno adoRecordset![Sname] = txtSname adoRecordset![Dbms] = txtDbms adoRecordset![VB] = txtVB adoRecordset![Java] = txtJava adoRecordset![Rmt] = txtRMT adoRecordset![VbLab] = txtVBlab adoRecordset![TOTAL] = txtTotal adoRecordset![AVERAGE] = txtaverage adoRecordset![Class] = txtClass adoRecordset![RESULT] = txtResult adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery txtRno = "" Call ClearFields End Sub

Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from MarkSheet where Rno='" & txtRno & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst Call DisplayRecord: MsgBox "First Record" End If End Sub Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast Call DisplayRecord MsgBox "Last Record" End If End Sub Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord End If

End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub Private Sub DisplayRecord() txtRno = adoRecordset![Rno] txtRegno = adoRecordset![Regno] txtSname = adoRecordset![Sname] txtDbms = adoRecordset![Dbms] txtVB = adoRecordset![VB] txtJava = adoRecordset![Java] txtRMT = adoRecordset![Rmt] txtVBlab = adoRecordset![VbLab] txtTotal = Val(adoRecordset![TOTAL]) txtaverage = Val(adoRecordset![AVERAGE]) txtClass = adoRecordset![Class] txtResult = adoRecordset![RESULT] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery Call CommitQuery MsgBox "Record Deleted", vbInformation txtRno = "" Call ClearFields End If End Sub

Private Sub txtVBlab_LostFocus() txtTotal = Val(txtDbms) + Val(txtVB) + Val(txtJava) + Val(txtRMT) + Val(txtVBlab) txtaverage = Val(txtTotal) / 5 If Val(txtDbms) > 40 And Val(txtVB) > 40 And Val(txtJava) > 40 And val(txtRMT) > 40 And Val(txtVBlab) > 40 Then txtResult = "Pass" Else txtResult = "Fail" End If If Val(txtaverage) > 80 Then txtClass = "Distinction" ElseIf Val(txtaverage) >= 60 Then txtClass = "First" ElseIf Val(txtaverage) >= 50 Then txtClass = "Second" End If End Sub

Student Information System


Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott; Password=tiger;Data Source=Information;Persist Security Info=False" Call SelectQuery cbxSex.Clear: cbxSex.AddItem "Sex": cbxSex.AddItem "Male": cbxSex.AddItem "Female" cbxSex.ListIndex = 0 End Sub Private Sub Form_Activate() txtRno = "": Call ClearFields: End Sub txtRno.SetFocus

Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Information" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() txtRegno = "" txtSname = "" cbxSex.ListIndex = 0 txtDOB = "" txtDegree = "" txtDepartment = "" txtPeriod = "" txtAddress = "" txtPhone = "" txtEmail = "" txtRno.SetFocus

End Sub Private Sub cmdClose_Click() txtRno = "" Call ClearFields Me.Hide End Sub Private Sub cmdAdd_Click() txtRno = "" Call ClearFields If adoRecordset.EOF then txtRno=1 Else adoRecordset.MoveLast txtRno= val(adoRecordset![Rno]) +1 End If txtEmpName.SetFocus End Sub Private Sub cmdSave_Click() If txtRno = "" Then MsgBox "Enter the Roll number", vbInformation txtRno.SetFocus Exit Sub End If If txtRegno = "" Then MsgBox "Enter the Register number", vbInformation txtRegno.SetFocus Exit Sub End If If txtSname = "" Then MsgBox "Enter the Student Name", vbInformation txtSname.SetFocus Exit Sub End If If cbxSex.ListIndex = 0 Then MsgBox "Enter the Sex", vbInformation cbxSex.SetFocus Exit Sub End If

If txtDOB = "" Then MsgBox "Enter the Date of Birth", vbInformation txtDOB.SetFocus Exit Sub End If If txtAddress = "" Then MsgBox "Enter the Address", vbInformation txtAddress.SetFocus Exit Sub End If If txtPhone = "" Then MsgBox "Enter the Phone", vbInformation txtPhone.SetFocus Exit Sub End If If txtEmail = "" Then MsgBox "Enter the Email", vbInformation txtEmail.SetFocus Exit Sub End If If txtPeriod = "" Then MsgBox "Enter the Period of Study", vbInformation txtPeriod.SetFocus Exit Sub End If Call DeleteQuery Call SelectQuery adoRecordset.AddNew adoRecordset![Rno] = txtRno adoRecordset![Regno] = txtRegno adoRecordset![Sname] = txtSname adoRecordset![Sex] = cbxSex.Text adoRecordset![dob] = txtDOB adoRecordset![Department] = txtDepartment adoRecordset![Period] = txtPeriod adoRecordset![Degree] = txtDegree adoRecordset![Address] = txtAddress adoRecordset![Phone] = txtPhone adoRecordset![Email] = txtEmail

adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery txtRno = "" Call ClearFields End Sub Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from Information where Rno='" & txtRno & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst Call DisplayRecord: MsgBox "First Record" End If End Sub Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast Call DisplayRecord MsgBox "Last Record" End If End Sub

Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord End If End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub Private Sub DisplayRecord() txtRno = adoRecordset![Rno] txtRegno = adoRecordset![Regno] txtSname = adoRecordset![Sname] cbxSex.Text = adoRecordset![Sex] txtDOB = Format(adoRecordset![dob], "dd-mmm-yyyy") txtDegree = adoRecordset![Degree] txtDepartment = adoRecordset![Department] txtPeriod = adoRecordset![Period] txtAddress = adoRecordset![Address] txtPhone = adoRecordset![Phone] txtEmail = adoRecordset![Email] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery: Call CommitQuery MsgBox "Record Deleted", vbInformation txtRno = "": Call ClearFields End If

End Sub

Library Information System


Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott; Password=tiger;Data Source=Library;Persist Security Info=False" Call SelectQuery End Sub Private Sub Form_Activate() txtAno = "" Call ClearFields txtAno.SetFocus End Sub Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Library" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() txtAname = "" txtTitle = "" txtSubject = "" txtPublisher = "" txtIsdn = "" txtPrice = "" txtEdition = "" txtAno.SetFocus End Sub Private Sub cmdClose_Click() txtAno = "" Call ClearFields Me.Hide

End Sub Private Sub cmdAdd_Click() txtAno = "" Call ClearFields If adoRecordset.EOF then txtAno=1 Else adoRecordset.MoveLast txtAno= val(adoRecordset![Ano]) +1 End If txtAName.SetFocus End Sub Private Sub cmdSave_Click() If txtAno = "" Then MsgBox "Enter the Accession number", vbInformation txtAno.SetFocus Exit Sub End If If txtAname = "" Then MsgBox "Enter the Author Name", vbInformation txtAname.SetFocus Exit Sub End If If txtSubject = "" Then MsgBox "Enter the Subject", vbInformation txtSubject.SetFocus Exit Sub End If If txtPublisher = "" Then MsgBox "Enter the Publisher", vbInformation txtPublisher.SetFocus Exit Sub End If If txtIsdn = "" Then MsgBox "Enter the ISDN", vbInformation txtIsdn.SetFocus Exit Sub End If If txtEdition = "" Then MsgBox "Enter the Edition", vbInformation txtEdition.SetFocus: Exit Sub

End If If txtPrice = "" Then MsgBox "Enter the Price", vbInformation txtPrice.SetFocus Exit Sub End If Call DeleteQuery Call SelectQuery adoRecordset.AddNew adoRecordset![Ano] = txtAno adoRecordset![Aname] = txtAname adoRecordset![Title] = txtTitle adoRecordset![Subject] = txtSubject adoRecordset![Publisher] = txtPublisher adoRecordset![Isdn] = txtIsdn adoRecordset![Edition] = txtEdition adoRecordset![Price] = txtPrice adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery txtAno = "" Call ClearFields End Sub Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from Library where Ano='" txtAno & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub

Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst Call DisplayRecord MsgBox "First Record" End If End Sub Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast Call DisplayRecord MsgBox "Last Record" End If End Sub Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord End If End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub

Private Sub DisplayRecord() txtAno = adoRecordset![Ano] txtAname = adoRecordset![Aname] txtTitle = adoRecordset![Title] txtSubject = adoRecordset![Subject] txtPublisher = adoRecordset![Publisher] txtIsdn = adoRecordset![Isdn] txtEdition = adoRecordset![Edition] txtPrice = adoRecordset![Price] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery Call CommitQuery MsgBox "Record Deleted", vbInformation Call ClearFields End If End Sub

Electricity Information System


Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott;Password=tiger;Data Source=Electricity;Persist Security Info=False" Call SelectQuery End Sub Private Sub Form_Activate() txtCno = "" Call ClearFields txtCno.SetFocus End Sub Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Electricity" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() txtCname = "" txtAddress = "" txtPrevious = "" txtCurrent = "" txtRemaining = "" cbxType.ListIndex = 0 cbxPlace.ListIndex = 0 cbxMode.ListIndex = 0 txtAmount = "" 'txtDoc = "" txtCno.SetFocus End Sub

Private Sub cmdClose_Click() txtCno = "" Call ClearFields Me.Hide End Sub Private Sub cmdAdd_Click() txtCno = "" Call ClearFields If adoRecordset.EOF then txtCno=1 Else adoRecordset.MoveLast txtCno= val(adoRecordset![Cno]) +1 End If txtCname.SetFocus End Sub Private Sub cmdSave_Click() If txtCno = "" Then MsgBox "Enter the Electricity number", vbInformation txtCno.SetFocus Exit Sub End If If txtCno = "" Then MsgBox "Enter the Consumer number", vbInformation txtCno.SetFocus Exit Sub End If If txtCname = "" Then MsgBox "Enter the Consumer Name", vbInformation txtCname.SetFocus Exit Sub End If If txtPrevious = "" Then MsgBox "Enter the Previous Reading", vbInformation txtPrevious.SetFocus Exit Sub End If If txtCurrent = "" Then MsgBox "Enter the Current Reading", vbInformation txtCurrent.SetFocus Exit Sub

End If If cbxType.ListIndex = 0 Then MsgBox "Enter the place of payment", vbInformation cbxPlace.SetFocus Exit Sub End If If cbxPlace.ListIndex = 0 Then MsgBox "Enter the place of payment", vbInformation cbxPlace.SetFocus Exit Sub End If If cbxMode.ListIndex = 0 Then MsgBox "Enter the mode of payment", vbInformation cbxMode.SetFocus Exit Sub End If Call DeleteQuery Call SelectQuery adoRecordset.AddNew adoRecordset![cno] = Val(txtCno) adoRecordset![cno] = txtCno adoRecordset![Cname] = txtCname adoRecordset![Address] = txtAddress adoRecordset![Previous] = Val(txtPrevious) adoRecordset![Current1] = Val(txtCurrent) adoRecordset![Remain] = Val(txtRemaining) adoRecordset![Type] = cbxType.Text adoRecordset![Place] = cbxPlace.Text adoRecordset![Modes] = cbxMode.Text adoRecordset![amount] = Val(txtAmount) adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery txtCno = "" Call ClearFields End Sub

Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from Electricity where Cno='" & txtCno & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst Call DisplayRecord MsgBox "First Record" End If End Sub Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast Call DisplayRecord MsgBox "Last Record" End If End Sub Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord

End If End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub Private Sub DisplayRecord() txtCno = adoRecordset![cno] txtCno = adoRecordset![cno] txtCname = adoRecordset![Cname] txtAddress = adoRecordset![Address] txtPrevious = adoRecordset![Previous] txtCurrent = adoRecordset![Current1] txtRemaining = adoRecordset![Remain] cbxType.Text = adoRecordset![Type] cbxPlace.Text = adoRecordset![Place] cbxMode.Text = adoRecordset![Modes] txtAmount = adoRecordset![amount] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery: Call CommitQuery MsgBox "Record Deleted", vbInformation Call ClearFields End If End Sub Private Sub cbxType_Click() If cbxType.ListIndex = 1 Then If Val(txtRemaining) > 0 And Val(txtRemaining) < 100 Then txtAmount = Val(txtRemaining) * 0.8 ElseIf Val(txtRemaining) >= 100 And Val(txtRemaining) < 500 Then txtAmount = Val(txtRemaining) * 1 ElseIf Val(txtRemaining) >= 500 Then

txtAmount = Val(txtRemaining) * 1.5 End If ElseIf cbxType.ListIndex = 2 Then txtAmount = Val(txtRemaining) * 2 End If End Sub Private Sub txtCurrent_LostFocus() If Val(txtCurrent) > Val(txtPrevious) Then txtRemaining = Val(txtCurrent) - Val(txtPrevious) Else MsgBox "Current Reading Calls should greater than Previous Reading Calls" txtCurrent = "" txtCurrent.SetFocus End If End Sub

Telephone Directory System


Dim adoConnection As ADODB.Connection Dim adoRecordset As ADODB.Recordset Dim adoCommand As ADODB.Command Private Sub Form_Load() Set adoConnection = New ADODB.Connection adoConnection.Open "Provider=MSDASQL.1;User ID=scott; Password=tiger; Data Source=Telephone; Persist Security Info=False" Call SelectQuery End Sub Private Sub Form_Activate() txtTno = "" Call ClearFields txtDoc.Text = Format(Now, "dd/mmmm/yyyy hh:mm:ss") End Sub Private Sub SelectQuery() Set adoRecordset = New ADODB.Recordset adoRecordset.ActiveConnection = adoConnection adoRecordset.Source = "Select * from Telephone" adoRecordset.CursorLocation = adUseClient adoRecordset.CursorType = adOpenDynamic adoRecordset.LockType = adLockOptimistic adoRecordset.Open End Sub Private Sub ClearFields() txtCode = "" txtTno = "" txtCno = "" txtCname = "" txtAddress = "" txtPrevious = "" txtCurrent = "" txtRemaining = "" cbxType.ListIndex = 0 cbxPlace.ListIndex = 0 cbxMode.ListIndex = 0 txtAmount = "" txtDoc = ""

txtTno.SetFocus End Sub Private Sub cmdClose_Click() txtTno = "" Call ClearFields Me.Hide End Sub Private Sub cmdAdd_Click() txtTno = "" Call ClearFields If adoRecordset.EOF then txtEmpId=1 Else adoRecordset.MoveLast txtTno= val(adoRecordset![Tno]) +1 End If txtTName.SetFocus End Sub Private Sub cmdSave_Click() If txtTno = "" Then MsgBox "Enter the Telephone number", vbInformation txtTno.SetFocus Exit Sub End If If txtCno = "" Then MsgBox "Enter the Consumer number", vbInformation txtCno.SetFocus Exit Sub End If If txtCname = "" Then MsgBox "Enter the Consumer Name", vbInformation txtCname.SetFocus Exit Sub End If If txtPrevious = "" Then MsgBox "Enter the Previous Reading", vbInformation txtPrevious.SetFocus Exit Sub End If

If txtCurrent = "" Then MsgBox "Enter the Current Reading", vbInformation txtCurrent.SetFocus Exit Sub End If If cbxType.ListIndex = 0 Then MsgBox "Enter the place of payment", vbInformation cbxPlace.SetFocus Exit Sub End If If cbxPlace.ListIndex = 0 Then MsgBox "Enter the place of payment", vbInformation cbxPlace.SetFocus Exit Sub End If If cbxMode.ListIndex = 0 Then MsgBox "Enter the mode of payment", vbInformation cbxMode.SetFocus Exit Sub End If Call DeleteQuery Call SelectQuery adoRecordset.AddNew adoRecordset![code] = Val(txtCode) adoRecordset![Tno] = Val(txtTno) adoRecordset![Cno] = txtCno adoRecordset![Cname] = txtCname adoRecordset![Address] = txtAddress adoRecordset![Previous] = Val(txtPrevious) adoRecordset![Current1] = Val(txtCurrent) adoRecordset![Remain] = Val(txtRemaining) adoRecordset![Type] = cbxType.Text adoRecordset![Place] = cbxPlace.Text adoRecordset![Modes] = cbxMode.Text adoRecordset![amount] = Val(txtAmount) adoRecordset.Update MsgBox "Record Saved", vbInformation Call CommitQuery

txtTno = "" Call ClearFields End Sub Private Sub DeleteQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Delete from Telephone where Tno='" & txtTno & "'" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub CommitQuery() Set adoCommand = New ADODB.Command adoCommand.ActiveConnection = adoConnection adoCommand.CommandText = "Commit" adoCommand.CommandType = adCmdText adoCommand.Execute End Sub Private Sub cmdFirst_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveFirst: Call DisplayRecord MsgBox "First Record" End If End Sub Private Sub cmdLast_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveLast: Call DisplayRecord MsgBox "Last Record" End If End Sub Private Sub cmdNext_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MoveNext If adoRecordset.EOF Then adoRecordset.MoveLast End If Call DisplayRecord

End If End Sub Private Sub cmdPrevious_Click() If adoRecordset.EOF Then MsgBox "There is no Record", vbInformation Else adoRecordset.MovePrevious If adoRecordset.BOF Then adoRecordset.MoveFirst End If Call DisplayRecord End If End Sub Private Sub DisplayRecord() txtCode = adoRecordset![code] txtTno = adoRecordset![Tno] txtCno = adoRecordset![Cno] txtCname = adoRecordset![Cname] txtAddress = adoRecordset![Address] txtPrevious = adoRecordset![Previous] txtCurrent = adoRecordset![Current1] txtRemaining = adoRecordset![Remain] cbxType.Text = adoRecordset![Type] cbxPlace.Text = adoRecordset![Place] cbxMode.Text = adoRecordset![Modes] txtAmount = adoRecordset![amount] End Sub Private Sub cmdDelete_Click() msg = MsgBox("Do you want to delete this record?", vbYesNo) If msg = vbYes Then Call DeleteQuery Call CommitQuery MsgBox "Record Deleted", vbInformation Call ClearFields End If End Sub Private Sub cbxType_Click() If cbxType.ListIndex = 1 Then If Val(txtRemaining) > 0 And Val(txtRemaining) < 100 Then txtAmount = Val(txtRemaining) * 0.8 ElseIf Val(txtRemaining) >= 100 And Val(txtRemaining) <

500 Then txtAmount = Val(txtRemaining) * 1 ElseIf Val(txtRemaining) >= 500 Then txtAmount = Val(txtRemaining) * 1.5 End If ElseIf cbxType.ListIndex = 2 Then txtAmount = Val(txtRemaining) * 2 End If End Sub Private Sub txtCurrent_LostFocus() If Val(txtCurrent) > Val(txtPrevious) Then txtRemaining = Val(txtCurrent) - Val(txtPrevious) Else MsgBox "Current Reading Calls should greater than Previous Reading Calls" txtCurrent = "" txtCurrent.SetFocus End If End Sub

You might also like