• No results found

Phase 4: Final Project

4.3 Source Code

Module1.bas

Option Explicit

Public Sub connection(ByRef dConnection As ADODB.connection, ByVal dLocation As String)

dConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &

dLocation & ";Persist Security Info=False;"

End Sub

Public Sub recordset(ByRef sRecordset As ADODB.recordset, ByRef sConnection As ADODB.connection, ByVal sSQL As String)

With sRecordset

.CursorLocation = adUseClient

.Open sSQL, sConnection, adOpenKeyset, adLockOptimistic End With

End Sub

Sub main()

frmLogin.txtUser.Text = ""

frmLogin.txtPW.Text = ""

frmLogin.Show vbModal End Sub"

frmMain.frm

Private Sub Form_Load() Call main

End Sub

Private Sub paymentsets_Click()

frmPaymentSettings.Show vbModal End Sub

Private Sub sysets_Click() frmSYSettings.Show vbModal End Sub

Private Sub close_Click() End

End Sub

Private Sub eleminfo_Click() frmElemInfo.Show vbModal End Sub

> frmLogin.frm

Private Sub cmdExit_Click() End

End Sub

Private Sub cmdLogin_Click() Dim uid, pw As String

uid = "admin"

pw = "password"

If txtUser.Text = uid And txtPW.Text = pw Then MsgBox "Login Successfully Granted!", vbInformation Unload Me

Else

MsgBox "Invalid username or password!", vbExclamation txtUser.Text = ""

txtPW.Text = ""

txtUser.SetFocus End If

End Sub

Private Sub Form_Load() cmdExit.Cancel = True cmdLogin.Default = True txtPW.PasswordChar = "*"

End Sub

> frmElemInfo.frm

Private Sub cmdAssessment_Click()

If ListView1.ListItems.Count < 1 Then MsgBox "No record found.", vbExclamation, "List of Students": Exit Sub

With frmAssessment

.txtStudID.Text = ListView1.SelectedItem

.txtStudNum.Text = ListView1.SelectedItem.SubItems(1) .txtLastN.Text = ListView1.SelectedItem.SubItems(2) .txtFirstN.Text = ListView1.SelectedItem.SubItems(3) .txtMI.Text = ListView1.SelectedItem.SubItems(4) .txtGender.Text = ListView1.SelectedItem.SubItems(5) .txtSY.Text = ListView1.SelectedItem.SubItems(11)

.txtElemLevel.Text = ListView1.SelectedItem.SubItems(12) .Show vbModal

End With End Sub

Private Sub cmdDelete_Click()

Dim cndelete As New ADODB.connection Dim rsdelete As New ADODB.recordset Dim condition As String

If ListView1.ListItems.Count < 1 Then MsgBox "No record found.", vbExclamation, "List of Students": Exit Sub

condition = MsgBox("Are you sure you want to delete: " & "'" &

ListView1.SelectedItem.SubItems(2) & ", " &

ListView1.SelectedItem.SubItems(3) & " " &

ListView1.SelectedItem.SubItems(4) & "'" & "?", vbYesNo, "Confirm Delete") If condition = vbNo Then

Exit Sub Else

Call connection(cndelete, App.Path & "\Database.mdb")

Call recordset(rsdelete, cndelete, "SELECT * FROM tblStudent WHERE studentID = " & ListView1.SelectedItem & "")

With rsdelete

Set cndelete = Nothing Set rsdelete = Nothing End Sub

Private Sub cmdEdit_Click()

If ListView1.ListItems.Count < 1 Then MsgBox "No record found.", vbExclamation, "List of Students": Exit Sub

With frmEditStudent

.txtStudID.Text = ListView1.SelectedItem

.txtStudNum.Text = ListView1.SelectedItem.SubItems(1) .txtLastN.Text = ListView1.SelectedItem.SubItems(2) .txtFirstN.Text = ListView1.SelectedItem.SubItems(3) .txtMI.Text = ListView1.SelectedItem.SubItems(4)

.cmbGender.Text = ListView1.SelectedItem.SubItems(5) .txtAge.Text = ListView1.SelectedItem.SubItems(6) .txtBdate.Text = ListView1.SelectedItem.SubItems(7) .txtAddress.Text = ListView1.SelectedItem.SubItems(8) .txtPG.Text = ListView1.SelectedItem.SubItems(9)

.txtContactNum.Text = ListView1.SelectedItem.SubItems(10) .comboSY.Text = ListView1.SelectedItem.SubItems(11) .comboElem.Text = ListView1.SelectedItem.SubItems(12) .comboPT.Text = ListView1.SelectedItem.SubItems(13) .Show vbModal

End With End Sub

Private Sub cmdNew_Click() frmNewStudent.Show vbModal End Sub

Private Sub comboLevel_Click() Call viewStudent

End Sub

Private Sub comboSY_Click() comboLevel.Enabled = True If ListView1.Visible = True Then Call comboLevel_Click

End If End Sub

Private Sub Form_Load() Call viewSY

Call viewLevel Call viewStudent

ListView1.Visible = False comboLevel.Enabled = False cmdAssessment.Enabled = False cmdEdit.Enabled = False

cmdDelete.Enabled = False

ListView1.ColumnHeaders.Item(1).Width = "0"

End Sub

Public Sub viewLevel()

Dim cncmblevel As New ADODB.connection Dim rscmblevel As New ADODB.recordset

Call connection(cncmblevel, App.Path & "\Database.mdb")

Call recordset(rscmblevel, cncmblevel, "SELECT * FROM tblElementaryLevel ORDER BY elementaryLevel ASC")

Do Until rscmblevel.EOF

comboLevel.AddItem rscmblevel!elementarylevel rscmblevel.MoveNext

Loop

Set cncmblevel = Nothing Set rscmblevel = Nothing End Sub

Public Sub viewSY()

Dim cncmbsy As New ADODB.connection Dim rscmbsy As New ADODB.recordset

Call connection(cncmbsy, App.Path & "\Database.mdb")

Call recordset(rscmbsy, cncmbsy, "SELECT * FROM tblSchoolYear ORDER BY schoolYear ASC")

Do Until rscmbsy.EOF

comboSY.AddItem rscmbsy!schoolYear rscmbsy.MoveNext

Loop

Set cncmbsy = Nothing Set rscmbsy = Nothing End Sub

Public Sub viewStudent()

Dim cnStud As New ADODB.connection Dim rsStud As New ADODB.recordset

ListView1.Visible = True

Call connection(cnStud, App.Path & "\Database.mdb")

Call recordset(rsStud, cnStud, "SELECT * FROM tblStudent WHERE schoolYear

= '" & comboSY.Text & "' AND elementaryLevel = '" & comboLevel.Text & "' ORDER BY studentnumber ASC")

Dim X

cmdAssessment.Enabled = True

cmdEdit.Enabled = True cmdDelete.Enabled = True

'ListView1.ListItems.Item(1).Width = "0"

Set cnStud = Nothing Set rsStud = Nothing

Dim cnCount As New ADODB.connection Dim rsCount As New ADODB.recordset

Call connection(cnCount, App.Path & "\Database.mdb")

Call recordset(rsCount, cnCount, "SELECT COUNT(studentid) as sumstudent FROM tblStudent WHERE elementaryLevel = '" & comboLevel.Text & "'")

lblcountstud.Caption = rsCount!sumstudent Set cnCount = Nothing

Set rsCount = Nothing Exit Sub

End Sub

> frmNewStudent.frm Private Sub cmdSave_Click()

Dim cnaddnew As New ADODB.connection Dim rsaddnew As New ADODB.recordset

If txtStudNum.Text <> "" And txtLastN.Text <> "" And txtFirstN.Text <> ""

And txtMI.Text <> "" And cmbGender.Text <> "" And txtAge.Text <> "" And txtBdate.Text <> "" And txtAddress.Text <> "" And txtPG.Text <> "" And txtContactNum.Text <> "" And comboPT.Text <> "" And comboElem.Text

<> "" And comboPT.Text <> "" And comboSY.Text <> "" Then Call connection(cnaddnew, App.Path & "\Database.mdb")

Call recordset(rsaddnew, cnaddnew, "INSERY INTO tblStudent (studentnumber,lastname,firstname,mi,gender,age,birthdate,address,parentg uardian,contactnum,paymentType,elementaryLevel,schoolYear) VALUES ('" &

txtStudNum.Text & "','" & txtLastN.Text & "','" & txtFirstN.Text & "','" &

txtMI.Text & "','" & cmbGender.Text & "','" & txtAge.Text & "','" &

txtBdate.Text & "','" & txtAddress.Text & "','" & txtPG.Text & "','" &

txtContactNum.Text & "','" & comboPT.Text & "','" & comboElem.Text & "','" &

comboSY.Text & "');")

MsgBox txtLastN.Text & ", " & txtFirstN.Text & " " & txtMI.Text & " is successful added to your database!", vbInformation

Unload Me Else

MsgBox "All fields are required!", vbExclamation End If

Set cnaddnew = Nothing Set rsaddnew = Nothing End Sub

Private Sub Form_Load() Call viewLevel

Public Sub setnum()

Dim cnsetnum As New ADODB.connection Dim rssetnum As New ADODB.recordset Dim idno As Integer

Call connection(cnsetnum, App.Path & "\Database.mdb")

Call recordset(rssetnum, cnsetnum, "SELECT * FROM tblStudent")

If rssetnum.RecordCount = 0 Then idno = 1

Else

rssetnum.MoveLast

idno = rssetnum.Fields("studentid") + 1 End If

txtStudNum.Text = Format(Now(), "yyyy-") & Format(idno, "000") End Sub

Public Sub cleared()

txtStudNum.Enabled = False txtStudID.Enabled = False txtStudID.Text = ""

txtStudNum.Text = ""

txtLastN.Text = ""

txtFirstN.Text = ""

txtMI.Text = ""

txtAge.Text = ""

txtBdate.Text = ""

txtAddress.Text = ""

txtPG.Text = ""

txtContactNum.Text = ""

comboPT.AddItem "Cash"

comboPT.AddItem "Installment"

cmbGender.AddItem "Male"

cmbGender.AddItem "Female"

End Sub

Public Sub viewLevel()

Dim cncmblevel As New ADODB.connection Dim rscmblevel As New ADODB.recordset

Call connection(cncmblevel, App.Path & "\Database.mdb")

Call recordset(rscmblevel, cncmblevel, "SELECT * FROM tblElementaryLevel ORDER BY elementaryLevel ASC")

Do Until rscmblevel.EOF

comboElem.AddItem rscmblevel!elementarylevel rscmblevel.MoveNext

Loop

Set cncmblevel = Nothing Set rscmblevel = Nothing End Sub

Public Sub viewSY()

Dim cncmbsy As New ADODB.connection Dim rscmbsy As New ADODB.recordset

Call connection(cncmbsy, App.Path & "\Database.mdb")

Call recordset(rscmbsy, cncmbsy, "SELECT * FROM tblSchoolYear ORDER BY schoolYear ASC")

Do Until rscmbsy.EOF

comboSY.AddItem rscmbsy!schoolYear rscmbsy.MoveNext

Loop

Set cncmbsy = Nothing

Set rscmbsy = Nothing End Sub

Public Sub tabindexes() txtLastN.TabIndex = 1 txtFirstN.TabIndex = 2 txtMI.TabIndex = 3

cmbGender.TabIndex = 4 txtAge.TabIndex = 5 txtBdate.TabIndex = 6 txtAddress.TabIndex = 7 txtPG.TabIndex = 8

txtContactNum.TabIndex = 9 comboSY.TabIndex = 10 comboElem.TabIndex = 11 comboPT.TabIndex = 12 cmdSave.TabIndex = 13 txtStudNum.TabStop = False txtStudID.TabStop = False End Sub

> frmEditStudent.frm Private Sub cmdSave_Click()

Dim cnupdate As New ADODB.connection Dim rsupdate As New ADODB.recordset

If txtStudNum.Text <> "" And txtLastN.Text <> "" And txtFirstN.Text <> ""

And txtMI.Text <> "" And cmbGender.Text <> "" And txtAge.Text <> "" And txtBdate.Text <> "" And txtAddress.Text <> "" And txtPG.Text <> "" And

txtContactNum.Text <> "" And comboPT.Text <> "" And comboElem.Text

<> "" And comboPT.Text <> "" And comboSY.Text <> "" Then Call connection(cnupdate, App.Path & "\Database.mdb")

Call recordset(rsupdate, cnupdate, "UPDATE tblStudent SET studentnumber = '" & txtStudNum.Text & "', lastname = '" & txtLastN.Text & "', firstname = '"

& txtFirstN.Text & "', mi = '" & txtMI.Text & "', gender = '" & cmbGender.Text

& "', age = '" & txtAge.Text & "', birthdate = '" & txtBdate.Text & "', address

= '" & txtAddress.Text & "', parentguardian = '" & txtPG.Text & "',

contactnum = '" & txtContactNum.Text & "', schoolyear = '" & comboSY.Text

& "', elementarylevel = '" & comboElem.Text & "', paymenttype = '" &

comboPT.Text & "'" & _

"WHERE studentid = " & txtStudID.Text & "")

MsgBox txtLastN.Text & ", " & txtFirstN.Text & " " & txtMI.Text & " is successful modified from your database!", vbInformation

Unload Me Else

MsgBox "All fields are required!", vbExclamation End If

Set cnupdate = Nothing Set rsupdate = Nothing End Sub

Private Sub Form_Load() Call viewLevel

Call viewSY Call cleared Call tabindexes End Sub

Public Sub cleared()

txtStudID.Enabled = False txtStudNum.Enabled = False txtStudID.Text = ""

txtLastN.Text = ""

txtFirstN.Text = ""

txtMI.Text = ""

txtAge.Text = ""

txtBdate.Text = ""

txtAddress.Text = ""

txtPG.Text = ""

txtContactNum.Text = ""

comboPT.AddItem "Cash"

comboPT.AddItem "Installment"

cmbGender.AddItem "Male"

cmbGender.AddItem "Female"

End Sub

Public Sub viewLevel()

Dim cncmblevel As New ADODB.connection Dim rscmblevel As New ADODB.recordset

Call connection(cncmblevel, App.Path & "\Database.mdb")

Call recordset(rscmblevel, cncmblevel, "SELECT * FROM tblElementaryLevel ORDER BY elementaryLevel ASC")

Do Until rscmblevel.EOF

comboElem.AddItem rscmblevel!elementarylevel rscmblevel.MoveNext

Loop

Set cncmblevel = Nothing Set rscmblevel = Nothing End Sub

Public Sub viewSY()

Dim cncmbsy As New ADODB.connection Dim rscmbsy As New ADODB.recordset

Call connection(cncmbsy, App.Path & "\Database.mdb")

Call recordset(rscmbsy, cncmbsy, "SELECT * FROM tblSchoolYear ORDER BY schoolYear ASC")

Do Until rscmbsy.EOF

comboSY.AddItem rscmbsy!schoolYear rscmbsy.MoveNext

Loop

Set cncmbsy = Nothing Set rscmbsy = Nothing End Sub

Public Sub tabindexes() txtLastN.TabIndex = 2 txtFirstN.TabIndex = 3 txtMI.TabIndex = 4

cmbGender.TabIndex = 5 txtAge.TabIndex = 6 txtBdate.TabIndex = 7 txtAddress.TabIndex = 8 txtPG.TabIndex = 9

txtContactNum.TabIndex = 10 comboSY.TabIndex = 11 comboElem.TabIndex = 12 comboPT.TabIndex = 13 cmdSave.TabIndex = 14 txtStudID.TabStop = False txtStudNum.TabStop = False End Sub

> frmAssessment.frm Private Sub cmbPT_Click() Call paymenttype

txtTotal.Text = Val(txtTFee.Text) + Val(txtDFee.Text) + Val(txtMFee.Text) End Sub

Private Sub cmdCancel_Click() Unload Me

End Sub

Private Sub cmdPrintShow_Click() With frmPrintLayout

.Label3.Caption = txtLastN.Text .Label5.Caption = txtFirstN.Text .Label7.Caption = txtMI.Text

.Label9.Caption = txtStudNum.Text .Label11.Caption = txtGender.Text .Label13.Caption = txtSY.Text

.Label15.Caption = txtElemLevel.Text .Label17.Caption = cmbPT.Text

.Label19.Caption = txtTFee.Text .Label21.Caption = txtDFee.Text .Label23.Caption = txtMFee.Text

.Label26.Caption = "Total: " & txtTotal.Text .Show vbModal

End With End Sub

Private Sub Form_Load() Call cleared

cmbPT.AddItem "Cash"

cmbPT.AddItem "Installment"

Call paymenttype

txtTotal.Text = Val(txtTFee.Text) + Val(txtDFee.Text) + Val(txtMFee.Text) End Sub

Public Sub paymenttype()

Dim cnCash As New ADODB.connection Dim cnInst As New ADODB.connection Dim rsCash As New ADODB.recordset Dim rsInst As New ADODB.recordset If cmbPT.Text = "Cash" Then

Call connection(cnCash, App.Path & "\Database.mdb")

Call recordset(rsCash, cnCash, "SELECT * FROM tblAssessmentCash")

txtCashID.Text = rsCash!astCashID txtTFee.Text = rsCash!tuitionfee txtDFee.Text = rsCash!departmentfee txtMFee.Text = rsCash!miscfee

Set cnCash = Nothing Set rsCash = Nothing

ElseIf cmbPT.Text = "Installment" Then

Call connection(cnInst, App.Path & "\Database.mdb")

Call recordset(rsInst, cnInst, "SELECT * FROM tblAssessmentInstallment") txtInstID.Text = rsInst!astInstallmentID

txtTFee.Text = rsInst!tuitionfee txtDFee.Text = rsInst!departmentfee txtMFee.Text = rsInst!miscfee

Set cnInst = Nothing Set rsInst = Nothing End If

End Sub

Public Sub cleared() txtTFee.Text = ""

txtDFee.Text = ""

txtMFee.Text = ""

End Sub

frmSYSettings

Private Sub cmdDelete_Click()

Dim cndelete As New ADODB.connection

Dim rsdelete As New ADODB.recordset Dim condition As String

If ListView1.ListItems.Count < 1 Then MsgBox "No record found.", vbExclamation, "List of Students": Exit Sub

condition = MsgBox("Are you sure you want to delete: " &

ListView1.SelectedItem.SubItems(1) & "?", vbYesNo, "Confirm Delete") If condition = vbNo Then

Exit Sub Else

Call connection(cndelete, App.Path & "\Database.mdb")

Call recordset(rsdelete, cndelete, "SELECT * FROM tblSchoolYear WHERE syID=" & ListView1.SelectedItem & "")

With rsdelete .Delete End With End If

MsgBox "The Selected School Year is successful deleted from the your database!", vbExclamation

Call dataload

Set cndelete = Nothing Set rsdelete = Nothing End Sub

Private Sub cmdEdit_Click()

If ListView1.ListItems.Count < 1 Then MsgBox "No record found.", vbExclamation, "List of Students": Exit Sub

With frmEditSY

.txtSYID.Text = ListView1.SelectedItem

.txtSY.Text = ListView1.SelectedItem.SubItems(1) .Show vbModal

End With End Sub

Private Sub cmdNew_Click() frmNewSY.Show vbModal End Sub

Private Sub Form_Load() Call dataload

End Sub

Public Sub dataload()

Dim cnSY As New ADODB.connection Dim rsSY As New ADODB.recordset Dim X

Call connection(cnSY, App.Path & "\Database.mdb")

Call recordset(rsSY, cnSY, "SELECT * FROM tblSchoolYear") ListView1.ListItems.Clear

End With

Set rsSY = Nothing End Sub

frmNewSY.frm

Private Sub cmdSave_Click()

Dim cnaddnew As New ADODB.connection Dim rsaddnew As New ADODB.recordset If txtSY.Text <> "" Then

Call connection(cnaddnew, App.Path & "\Database.mdb")

Call recordset(rsaddnew, cnaddnew, "INSERT INTO tblSchoolYear(schoolYear) VALUES ('" & txtSY.Text & "');")

MsgBox "This school year is successful created to your database!", vbInformation

Unload Me

Unload frmSYSettings

frmSYSettings.Show vbModal

Else

MsgBox "All fields required", vbExclamation End If

End Sub

frmEditSY.frm

Private Sub cmdSave_Click()

Dim cnupdate As New ADODB.connection Dim rsupdate As New ADODB.recordset If txtSY.Text <> "" Then

Call connection(cnupdate, App.Path & "\Database.mdb")

Call recordset(rsupdate, cnupdate, "UPDATE tblSchoolYear SET schoolYear='"

& txtSY.Text & "'" & _

"WHERE syid=" & txtSYID.Text & "") Unload Me

frmSYSettings.dataload

MsgBox "The selected school year is successful modified!", vbInformation Else

MsgBox "That field are required!", vbExclamation End If

Set cnupdate = Nothing Set rsupdate = Nothing End Sub

frmPaymentSettings.frm Private Sub cmdCashSave_Click()

Dim cnupdate As New ADODB.connection Dim rsupdate As New ADODB.recordset

If txtCashTFee.Text <> "" And txtCashDFee.Text <> "" And txtCashMFee.Text <> "" Then

Call connection(cnupdate, App.Path & "\Database.mdb")

Call recordset(rsupdate, cnupdate, "UPDATE tblAssessmentCash SET tuitionfee = '" & txtCashTFee.Text & "', departmentfee = '" &

txtCashDFee.Text & "', miscfee = '" & txtCashMFee.Text & "'" & _ "WHERE astCashID = " & txtCashID.Text & "")

MsgBox "Cash is successful modified from your database!", vbInformation Unload Me

frmPaymentSettings.Show vbModal Else

MsgBox "All fields are required!", vbExclamation

End If

Set cnupdate = Nothing Set rsupdate = Nothing End Sub

Private Sub cmdInstSave_Click()

Dim cnupdate As New ADODB.connection Dim rsupdate As New ADODB.recordset

If txtInstTFee.Text <> "" And txtInstDFee.Text <> "" And txtInstMFee.Text

<> "" Then

Call connection(cnupdate, App.Path & "\Database.mdb")

Call recordset(rsupdate, cnupdate, "UPDATE tblAssessmentInstallment SET tuitionFee = '" & txtInstTFee.Text & "', departmentFee = '" & txtInstDFee.Text

& "', miscFee = '" & txtInstMFee.Text & "'" & _ "WHERE astInstallmentID = " & txtInstID.Text & "")

MsgBox "Installment is successful modified from your database!", vbInformation

Unload Me

frmPaymentSettings.Show vbModal Else

MsgBox "All fields are required!", vbExclamation End If

Set cnupdate = Nothing Set rsupdate = Nothing End Sub

Private Sub Form_Load() Call cleared

Call cash

Call installment End Sub

Public Function cleared() txtCashTFee.Text = ""

txtCashDFee.Text = ""

txtCashMFee.Text = ""

txtInstTFee.Text = ""

txtInstDFee.Text = ""

txtInstMFee.Text = ""

End Function

Public Sub cash()

Dim cnCash As New ADODB.connection Dim rsCash As New ADODB.recordset

Call connection(cnCash, App.Path & "\Database.mdb")

Call recordset(rsCash, cnCash, "SELECT * FROM tblAssessmentCash") txtCashID.Text = rsCash!astCashID

txtCashTFee.Text = rsCash!tuitionfee txtCashDFee.Text = rsCash!departmentfee txtCashMFee.Text = rsCash!miscfee

Set cnCash = Nothing Set rsCash = Nothing End Sub

Public Sub installment()

Dim cnInst As New ADODB.connection Dim rsInst As New ADODB.recordset

Call connection(cnInst, App.Path & "\Database.mdb")

Call recordset(rsInst, cnInst, "SELECT * FROM tblAssessmentInstallment") txtInstID.Text = rsInst!astInstallmentID

txtInstTFee.Text = rsInst!tuitionfee txtInstDFee.Text = rsInst!departmentfee txtInstMFee.Text = rsInst!miscfee

Set cnInst = Nothing Set rsInst = Nothing End Sub

frmPrintLayut.frm

Private Sub Command1_Click() Command1.Visible = False Command2.Visible = False frmPrintLayout.PrintForm Unload Me

End Sub

Private Sub Command2_Click() Unload Me

End Sub

Private Sub Form_Load()

Label24.Caption = "As of " & Time

Label25.Caption = "Date: " & Date End Sub

APPENDIXES

REFERENCES

Related documents