0% found this document useful (0 votes)
159 views29 pages

Source Code

This code is for a student record management system. It defines variables and connections to databases. It contains subroutines for loading and displaying student records from a database, searching records, adding/editing/deleting records, and validating input fields when saving or updating records.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views29 pages

Source Code

This code is for a student record management system. It defines variables and connections to databases. It contains subroutines for loading and displaying student records from a database, searching records, adding/editing/deleting records, and validating input fields when saving or updating records.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 29

-SOURCE CODE

frmStudent

Option Explicit
Dim dbStudent As New ADODB.Connection
Dim rsStudent As New ADODB.Recordset
Dim dbTemp As New ADODB.Connection
Dim rsTemp As New ADODB.Recordset
Dim dbTemp1 As New ADODB.Connection
Dim rsTemp1 As New ADODB.Recordset
Dim ctr As Integer

Sub Student(ByVal strSQL As String)


Dim x
With lv.ListItems
.Clear
OpenConn dbTemp, rsTemp, strSQL
While Not rsTemp.EOF
Set x = .Add(, , rsTemp.Fields("IDs"))
x.SubItems(1) = rsTemp.Fields("LastName")
x.SubItems(2) = rsTemp.Fields("FirstName")
x.SubItems(3) = rsTemp.Fields("MiddleName")
x.SubItems(4) = rsTemp.Fields("Age")
x.SubItems(5) = rsTemp.Fields("Gender")
rsTemp.MoveNext
Wend
CloseConn rsTemp, dbTemp
End With
End Sub

Private Sub cbo_Click(Index As Integer)


Select Case Index
Case 2
txtDetail(4).Text = Year(Now) - Val(cbo(2).Text)
End Select
End Sub

Private Sub cbo_KeyPress(Index As Integer, KeyAscii As Integer)


For Index = 0 To 5
KeyAscii = 0
Next Index
End Sub
Private Sub cboSearch_Click()
txtSearch.Text = ""
Select Case cboSearch.Text
Case "Student ID"
txtSearch.MaxLength = 8
txtSearch.SetFocus
Case "Last Name"
txtSearch.MaxLength = 25
txtSearch.SetFocus
Case "First Name"
txtSearch.MaxLength = 25
txtSearch.SetFocus
Case Else
txtSearch.MaxLength = 25
txtSearch.SetFocus
End Select
End Sub

Private Sub cboSearch_KeyPress(KeyAscii As Integer)


KeyAscii = 0
End Sub

Private Sub chk_Click(Index As Integer)


Select Case Index
Case 3
If chk(3).Value = 0 Then
txtDetail(11).Enabled = False
txtDetail(11).Text = ""
Else
txtDetail(11).Enabled = True
End If
End Select
End Sub

Private Sub cmdButton_Click(Index As Integer)


With rsStudent
Select Case Index
Case 0
ConView False
.AddNew
ClearFields
txtDetail(0).Text = Year(Now) & Format(.RecordCount, "0000")
txtDetail(1).SetFocus
cmdButton(5).Caption = "&Save"
Timer1.Enabled = True
Case 1
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to edit.", vbExclamation, "Edit"
Else
ConView False
cmdButton(5).Caption = "&Update"
txtDetail(1).SetFocus
End If
Case 2
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to delete.", vbExclamation, "Delete"
Else
If MsgBox("Are you sure that you want to delete this record?",
vbQuestion + vbYesNo, "Delete?") = vbYes Then
.Fields("Inactive") = True
.Update
MsgBox "Successfully Deleted!", vbInformation
Call cmdRefresh_Click
End If
End If
Case 3
Unload Me
Case 4
ConView True
.CancelUpdate
ClearFields
cmdButton(5).Caption = "&Save"
Timer1.Enabled = False
Call cmdRefresh_Click
txtSearch.SetFocus
Case 5
If txtDetail(1).Text = "" Then
MsgBox "Please, fill the last name text field.", vbExclamation,
"Empty Field"
txtDetail(1).SetFocus
ElseIf txtDetail(2).Text = "" Then
MsgBox "Please, fill the first name text field.", vbExclamation,
"Empty Field"
txtDetail(2).SetFocus
ElseIf txtDetail(3).Text = "" Then
MsgBox "Please, fill the middle name text field.", vbExclamation,
"Empty Field"
txtDetail(3).SetFocus
ElseIf Len(txtDetail(3).Text) = 1 Then
MsgBox "Please, fill the middle name text field not middle initial.",
vbExclamation, "Empty Field"
txtDetail(3).SetFocus
ElseIf cbo(0).Text = "" Then
MsgBox "Please, select birth month.", vbExclamation, "Empty Field"
cbo(0).SetFocus
ElseIf cbo(1).Text = "" Then
MsgBox "Please, select day of birth.", vbExclamation, "Empty Field"
cbo(1).SetFocus
ElseIf cbo(2).Text = "" Then
MsgBox "Please, select birth year.", vbExclamation, "Empty Field"
cbo(2).SetFocus
ElseIf cbo(3).Text = "" Then
MsgBox "Please, gender.", vbExclamation, "Empty Field"
cbo(3).SetFocus
ElseIf txtDetail(5).Text = "" Then
MsgBox "Please, fill the home address text field.", vbExclamation,
"Empty Field"
txtDetail(5).SetFocus
ElseIf txtDetail(6).Text = "" Then
MsgBox "Please, fill the city address text field.", vbExclamation,
"Empty Field"
txtDetail(6).SetFocus
ElseIf txtDetail(9).Text = "" Then
MsgBox "Please, fill the guardian name text field.", vbExclamation,
"Empty Field"
txtDetail(9).SetFocus
ElseIf Len(txtDetail(7).Text) < 7 And Len(txtDetail(7).Text) <> 0 Then
MsgBox "Invalid telephone number, it must contain 7 digit number.",
vbExclamation, "Empty Field"
txtDetail(7).SetFocus
ElseIf Len(txtDetail(8).Text) < 11 And Len(txtDetail(8).Text) <> 0 Then
MsgBox "Invalid mobile number, it must contain 11 digit number.",
vbExclamation, "Empty Field"
txtDetail(8).SetFocus
ElseIf Len(txtDetail(10).Text) < 11 And Len(txtDetail(10).Text) <> 0
Then
MsgBox "Invalid contact number, 7 digit number for telephone no. or
11 digit no. for mobile no.", vbExclamation, "Empty Field"
txtDetail(10).SetFocus
ElseIf txtDetail(12).Text = "" Then
MsgBox "Please, fill the previous average grade text field.",
vbExclamation, "Empty Field"
txtDetail(12).SetFocus
Else
If MsgBox("Are you sure that you want to save this record?",
vbQuestion + vbYesNo, "Save") = vbYes Then
SaveFields
.Update
MsgBox "Successfully Saved!", vbInformation, "Saved"
ConView True
Call cmdRefresh_Click
Call cmdRefresh_Click
ClearFields
txtSearch.SetFocus
End If
End If
End Select
End With
End Sub

Private Sub cmdConfirm_Click()


Dim dbTemp2 As New ADODB.Connection
Dim rsTemp2 As New ADODB.Recordset
OpenConn dbTemp2, rsTemp2, "SELECT * FROM tblStudent WHERE na='" &
txtFull.Text & "'"
With rsTemp2
If .EOF = False Then
MsgBox "Student name is already exist!", vbCritical, "Exist"
txtDetail(1) = ""
txtDetail(2) = ""
txtDetail(3) = ""
txtDetail(1).SetFocus
End If
End With
CloseConn rsTemp2, dbTemp2
Timer1.Enabled = True
End Sub

Private Sub cmdRefresh_Click()


Student "SELECT * FROM tblStudent WHERE Inactive=False"
ClearFields
Timer1.Enabled = False
txtSearch.Text = ""
cboSearch.Text = ""
End Sub

Private Sub cmdSearch_Click()


Select Case cboSearch.Text
Case "Student ID"
OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblStudent WHERE
Inactive=False AND IDs='" & txtSearch.Text & "'"
If rsTemp1.EOF = True Then
MsgBox "No student record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Student "SELECT * FROM tblStudent WHERE Inactive=False"
Else
Student "SELECT * FROM tblStudent WHERE Inactive=False AND
IDs='" & txtSearch.Text & "'"
End If
CloseConn rsTemp1, dbTemp1

Case "Last Name"


OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblStudent WHERE
Inactive=False AND LastName LIKE '%" & txtSearch.Text & "%'"
If rsTemp1.EOF = True Then
MsgBox "No student record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Student "SELECT * FROM tblStudent WHERE Inactive=False"
Else
Student "SELECT * FROM tblStudent WHERE Inactive=False AND
LastName LIKE '%" & txtSearch.Text & "%'"
End If
CloseConn rsTemp1, dbTemp1

Case "First Name"


OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblStudent WHERE
Inactive=False AND FirstName LIKE '%" & txtSearch.Text & "%'"
If rsTemp1.EOF = True Then
MsgBox "No student record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Student "SELECT * FROM tblStudent WHERE Inactive=False"
Else
Student "SELECT * FROM tblStudent WHERE Inactive=False AND
FirstName LIKE '%" & txtSearch.Text & "%'"
End If
CloseConn rsTemp1, dbTemp1

Case Else
MsgBox "No current record!", vbCritical, "No record"
Call cmdRefresh_Click
End Select
End Sub
Private Sub Form_Load()
OpenConn dbStudent, rsStudent, "SELECT * FROM tblStudent"
Student "SELECT * FROM tblStudent WHERE Inactive=False"
Timer1.Enabled = False
End Sub
Private Sub Form_Resize()
MidFrm Me, mdiMain
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)


CloseConn rsStudent, dbStudent
mdiMain.tmrSidePanelShow.Enabled = True
End Sub

Private Sub lv_ItemClick(ByVal Item As MSComctlLib.ListItem)


With rsStudent
.Requery
.Find "IDs='" & Item.Text & "'"
DisplayFields
Timer1.Enabled = False
End With
End Sub

Private Sub Timer1_Timer()


Call cmdConfirm_Click
End Sub

Private Sub txtDetail_Change(Index As Integer)


Select Case Index
Case 1
txtFull.Text = txtDetail(1).Text
Case 2
txtFull.Text = txtDetail(1).Text & ", " & txtDetail(2).Text
Case 3
txtFull.Text = txtDetail(1).Text & ", " & txtDetail(2).Text & " " &
txtDetail(3).Text
End Select
End Sub

Private Sub txtDetail_GotFocus(Index As Integer)


For Index = 0 To 12
Call high(txtDetail(Index))
Next Index
End Sub

Private Sub txtDetail_KeyPress(Index As Integer, KeyAscii As Integer)


Select Case Index
Case 1, 2, 3, 9, 11
If Not (KeyAscii >= 65 And KeyAscii <= 122 Or (KeyAscii = 32 Or
KeyAscii = 8)) Then
KeyAscii = 0
End If
Case 7, 8, 10, 12
KeyAscii = isNumber(KeyAscii)
End Select
End Sub

Private Sub txtDetail_LostFocus(Index As Integer)


For Index = 1 To 12
txtDetail(Index).Text = Upcase(txtDetail(Index))
Next Index
End Sub

Sub ConView(ByVal visi As Boolean)


Select Case visi
Case True
For ctr = 0 To 3
cmdButton(ctr).Visible = True
Next ctr
cmdRefresh.Visible = True
cmdButton(4).Visible = False
cmdButton(5).Visible = False
picEntry.Visible = True

Case False
For ctr = 0 To 3
cmdButton(ctr).Visible = False
Next ctr
cmdRefresh.Visible = False
cmdButton(4).Visible = True
cmdButton(5).Visible = True
picEntry.Visible = False
End Select
End Sub

Sub ClearFields()
txtDetail(0).Text = ""
txtDetail(1).Text = ""
txtDetail(2).Text = ""
txtDetail(3).Text = ""
txtDetail(4).Text = ""
txtDetail(5).Text = ""
txtDetail(6).Text = ""
txtDetail(7).Text = ""
txtDetail(8).Text = ""
txtDetail(9).Text = ""
txtDetail(10).Text = ""
txtDetail(11).Text = ""
txtDetail(12).Text = ""
cbo(0).Text = ""
cbo(1).Text = ""
cbo(2).Text = ""
cbo(3).Text = ""
cbo(4).Text = ""
cbo(5).Text = ""
chk(0).Value = 0
chk(1).Value = 0
chk(2).Value = 0
chk(3).Value = 0
End Sub

Sub DisplayFields()
With rsStudent
txtDetail(0).Text = .Fields("IDs")
txtDetail(1).Text = .Fields("LastName")
txtDetail(2).Text = .Fields("FirstName")
txtDetail(3).Text = .Fields("MiddleName")
txtDetail(4).Text = .Fields("Age")
txtDetail(5).Text = .Fields("Address")
txtDetail(6).Text = .Fields("City")
txtDetail(7).Text = .Fields("Telephone")
txtDetail(8).Text = .Fields("Mobile")
txtDetail(9).Text = .Fields("Guardian")
txtDetail(10).Text = .Fields("Contact")
txtDetail(11).Text = .Fields("School")
txtDetail(12).Text = .Fields("Ave")
cbo(0).Text = .Fields("BirthMonth")
cbo(1).Text = .Fields("BirthDay")
cbo(2).Text = .Fields("BirthYear")
cbo(3).Text = .Fields("Gender")
cbo(4).Text = .Fields("Religion")
cbo(5).Text = .Fields("Citizenship")
If .Fields("Certificate") = True Then
chk(0).Value = 1
Else
chk(0).Value = 0
End If

If .Fields("Card") = True Then


chk(1).Value = 1
Else
chk(1).Value = 0
End If

If .Fields("Diploma") = True Then


chk(2).Value = 1
Else
chk(2).Value = 0
End If

txtFull.Text = .Fields("na")
End With
End Sub

Sub SaveFields()
With rsStudent
.Fields("IDs") = txtDetail(0).Text
.Fields("LastName") = txtDetail(1).Text
.Fields("FirstName") = txtDetail(2).Text
.Fields("MiddleName") = txtDetail(3).Text
.Fields("Age") = txtDetail(4).Text
.Fields("Address") = txtDetail(5).Text
.Fields("City") = txtDetail(6).Text
If txtDetail(7).Text = "" Then
.Fields("Telephone") = "n/a"
Else
.Fields("Telephone") = txtDetail(7).Text
End If

If txtDetail(8).Text = "" Then


.Fields("Mobile") = "n/a"
Else
.Fields("Mobile") = txtDetail(8).Text
End If

If txtDetail(10).Text = "" Then


.Fields("Contact") = "n/a"
Else
.Fields("Contact") = txtDetail(10).Text
End If
.Fields("Guardian") = txtDetail(9).Text
If txtDetail(11).Text = "" Then
.Fields("School") = "n/a"
Else
.Fields("School") = txtDetail(11).Text
End If
.Fields("Ave") = txtDetail(12).Text
.Fields("BirthMonth") = cbo(0).Text
.Fields("BirthDay") = cbo(1).Text
.Fields("BirthYear") = cbo(2).Text
.Fields("Gender") = cbo(3).Text
.Fields("Religion") = cbo(4).Text
.Fields("Citizenship") = cbo(5).Text
.Fields("Certificate") = chk(0).Value
.Fields("Card") = chk(1).Value
.Fields("Diploma") = chk(2).Value
'chk(3).Value = .Fields("ID")
.Fields("na") = txtFull.Text
End With
End Sub

Private Sub txtSearch_KeyPress(KeyAscii As Integer)


Select Case cboSearch.Text
Case "Student ID"
If KeyAscii = 13 Then
Call cmdSearch_Click
End If
KeyAscii = isNumber(KeyAscii)
Case "Last Name", "First Name"
If KeyAscii = 13 Then
Call cmdSearch_Click
End If
If Not (KeyAscii >= 65 And KeyAscii <= 122 Or (KeyAscii = 32 Or KeyAscii =
8)) Then
KeyAscii = 0
End If
End Select
End Sub

frmEnrollment

Option Explicit
Dim dbEnroll As New ADODB.Connection
Dim rsEnroll As New ADODB.Recordset
Dim dbTemp As New ADODB.Connection
Dim rsTemp As New ADODB.Recordset
Dim dbTemp1 As New ADODB.Connection
Dim rsTemp1 As New ADODB.Recordset
Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset

Sub SaveEnroll()
With rsEnroll
.Fields(0) = txtDetail(0).Text
.Fields(1) = last
.Fields(2) = first
.Fields(3) = middle
.Fields(4) = txtDetail(1).Text
.Fields(5) = txtDetail(2).Text
.Fields(6) = txtDetail(3).Text

.Fields(7) = SY.Caption
.Fields(8) = txtDetail(12).Text
.Fields(9) = txtDetail(13).Text
.Fields(10) = txtDetail(6).Text
.Fields(11) = txtDetail(8).Text
'.Fields(13)=id
.Fields(14) = Date
.Fields(15) = Time
End With
End Sub

Sub ClearEnroll()
txtDetail(0).Text = ""
txtDetail(1).Text = ""
txtDetail(2).Text = ""
txtDetail(3).Text = ""
txtDetail(4).Text = ""
txtDetail(5).Text = ""
txtDetail(7).Text = ""
txtDetail(14).Text = ""
txtDetail(9).Text = ""
txtDetail(10).Text = ""
'txtDetail(11).Text = ""
txtDetail(12).Text = ""
txtDetail(13).Text = ""
txtDetail(6).Text = ""
txtDetail(8).Text = ""
lvSubject.ListItems.Clear
End Sub

Private Sub cmdButton_Click(Index As Integer)


Select Case Index
Case 0
If Val(txtDetail(4).Text) < Val(txtDetail(10).Text) Then
MsgBox "Not allowed in this section, because the previous grade of
this student is less than to minimum grade.": Exit Sub:
If MsgBox("Are you sure that you want to enroll this student?",
vbQuestion + vbYesNo, "Enroll") = vbYes Then
OpenConn dbEnroll, rsEnroll, "SELECT * FROM tblEnroll WHERE
ID='" & txtDetail(0).Text & "' AND SY='" & SY.Caption & "'"
With rsEnroll
If .EOF = True Then
.AddNew
SaveEnroll
.Update
MsgBox "The student must pay to the registrar before he/she
completely enroll for this school year.", vbInformation, "Enroll"
ClearEnroll
txtDetail(0).SetFocus
Else
MsgBox "This student has already enrolled for this school
year.", vbCritical, "Enrolled"
End If
End With
CloseConn rsEnroll, dbEnroll
End If
Case 1
Unload Me
End Select
End Sub

Private Sub cmdSearch_Click()


If txtDetail(0).Text = "" Then
MsgBox "Please, enter student number to search.", vbExclamation,
"Student Number"
txtDetail(0).SetFocus
Else
OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblStudent WHERE
IDs='" & txtDetail(0).Text & "'"
With rsTemp1
If .EOF = False Then
txtDetail(0).Text = .Fields("IDs")
txtDetail(1).Text = .Fields("LastName") & ", " & .Fields("FirstName")
txtDetail(2).Text = .Fields("Age")
txtDetail(3).Text = .Fields("Gender")
txtDetail(4).Text = .Fields("Ave")
last = .Fields("LastName")
first = .Fields("FirstName")
middle = .Fields("MiddleName")
Else
MsgBox "No record found!", vbCritical, "No record"
ClearFields
txtDetail(0).SetFocus

End If
End With
CloseConn rsTemp1, dbTemp1
End If
End Sub

Sub Information(ByVal strSQL As String)


Dim x
With lv.ListItems
.Clear
OpenConn dbTemp, rsTemp, strSQL
While Not rsTemp.EOF
Set x = .Add(, , rsTemp.Fields("IDs"))
lv.ListItems.Add , , "Name: " & rsTemp.Fields("na")
rsTemp.MoveNext
Wend
CloseConn rsTemp, dbTemp
End With
End Sub

Sub Subject(ByVal strSQL As String)


Dim x
With lvSubject.ListItems
.Clear
OpenConn db, rs, strSQL
While Not rs.EOF
Set x = .Add(, , rs.Fields(0))
x.SubItems(1) = rs.Fields(2)
x.SubItems(2) = rs.Fields(3)
x.SubItems(3) = rs.Fields(4)
x.SubItems(4) = rs.Fields(5) & "-" & rs.Fields(6)
x.SubItems(5) = rs.Fields(7)
x.SubItems(6) = rs.Fields(8)
rs.MoveNext
Wend
CloseConn rs, db
End With
End Sub

Sub ClearFields()
txtDetail(0).Text = ""
txtDetail(1).Text = ""
txtDetail(2).Text = ""
txtDetail(3).Text = ""
txtDetail(4).Text = ""
End Sub

Sub ClearFields2()
txtDetail(5).Text = ""
txtDetail(6).Text = ""
txtDetail(7).Text = ""
txtDetail(8).Text = ""
txtDetail(9).Text = ""
txtDetail(10).Text = ""
'txtDetail(11).Text = ""
txtDetail(12).Text = ""
txtDetail(13).Text = ""
txtDetail(14).Text = ""
End Sub

Private Sub cmdSearch2_Click()


If txtDetail(5).Text = "" Then
MsgBox "Please, enter section to search.", vbExclamation, "Section"
txtDetail(5).SetFocus
Else
OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblSection WHERE ID='"
& txtDetail(5).Text & "'"
With rsTemp1
If .EOF = False Then
txtDetail(6).Text = .Fields(1)
txtDetail(7).Text = .Fields(4)
txtDetail(8).Text = .Fields(5)
txtDetail(9).Text = .Fields(6)
txtDetail(10).Text = .Fields("MinGrade")
'txtDetail(11).Text = .Fields(9)
txtDetail(12).Text = .Fields(2)
txtDetail(13).Text = .Fields(3)
txtDetail(14).Text = .Fields("MaxGrade")
Subject "SELECT * FROM tblSchedule WHERE ID='" &
txtDetail(5).Text & "'" 'AND Section LIKE '" & txtDetail(6).Text & "'"
Else
MsgBox "No record found!", vbCritical, "No record"
ClearFields2
txtDetail(5).SetFocus

End If
End With
CloseConn rsTemp1, dbTemp1
End If
End Sub

Private Sub Form_Resize()


MidFrm Me, mdiMain
End Sub

Private Sub Form_Load()


OpenConn db, rs, "SELECT * FROM tblSetup"
SY.Caption = rs.Fields(3) & "-" & rs.Fields(4)
CloseConn rs, db
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)


mdiMain.tmrSidePanelShow.Enabled = True
End Sub

Private Sub txtDetail_KeyPress(Index As Integer, KeyAscii As Integer)


Select Case Index
Case 0
If KeyAscii = 13 Then
Call cmdSearch_Click
End If
KeyAscii = isNumber(KeyAscii)
Case 5
If KeyAscii = 13 Then
Call cmdSearch2_Click
End If
End Select
End Sub

frmTeacher

Option Explicit
Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim dbFaculty As New ADODB.Connection
Dim rsFaculty As New ADODB.Recordset
Dim dbTemp1 As New ADODB.Connection
Dim rsTemp1 As New ADODB.Recordset
Dim ctr As Integer

Sub Faculty(ByVal strSQL As String)


Dim x
With lv.ListItems
.Clear
OpenConn db, rs, strSQL
While Not rs.EOF
Set x = .Add(1, , rs.Fields(0))
x.SubItems(1) = rs.Fields(1)
x.SubItems(2) = rs.Fields(2)
x.SubItems(3) = rs.Fields(3)
x.SubItems(4) = rs.Fields(5)
rs.MoveNext
Wend
CloseConn rs, db
End With
End Sub

Private Sub cboSearch_Click()


txtSearch.Text = ""
Select Case cboSearch.Text
Case "Student ID"
txtSearch.MaxLength = 8
txtSearch.SetFocus
Case "Last Name"
txtSearch.MaxLength = 25
txtSearch.SetFocus
Case "First Name"
txtSearch.MaxLength = 25
txtSearch.SetFocus
Case Else
txtSearch.MaxLength = 25
txtSearch.SetFocus
End Select
End Sub

Private Sub cboSearch_KeyPress(KeyAscii As Integer)


KeyAscii = 0
End Sub
Private Sub cmdButton_Click(Index As Integer)
With rsFaculty
Select Case Index
Case 0
ConView False
.AddNew
ClearFields
txtDetail(0).Text = Format(.RecordCount, "0000")
txtDetail(1).SetFocus
cmdButton(5).Caption = "&Save"
Timer1.Enabled = True
Case 1
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to edit.", vbExclamation, "Edit"
Else
ConView False
cmdButton(5).Caption = "&Update"
txtDetail(1).SetFocus
End If
Case 2
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to delete.", vbExclamation, "Delete"
Else
If MsgBox("Are you sure that you want to delete this record?",
vbQuestion + vbYesNo, "Delete?") = vbYes Then
.Fields("Inactive") = True
.Update
MsgBox "Successfully Deleted!", vbInformation
Call cmdRefresh_Click
End If
End If
Case 3
Unload Me
Case 4
ConView True
.CancelUpdate
ClearFields
cmdButton(5).Caption = "&Save"
Timer1.Enabled = False
Call cmdRefresh_Click
txtSearch.SetFocus
Case 5
If txtDetail(1).Text = "" Then
MsgBox "Please, fill the last name text field.", vbExclamation,
"Empty Field"
txtDetail(1).SetFocus
ElseIf txtDetail(2).Text = "" Then
MsgBox "Please, fill the first name text field.", vbExclamation,
"Empty Field"
txtDetail(2).SetFocus
ElseIf txtDetail(3).Text = "" Then
MsgBox "Please, fill the middle name text field.", vbExclamation,
"Empty Field"
txtDetail(3).SetFocus
ElseIf Len(txtDetail(3).Text) = 1 Then
MsgBox "Please, fill the middle name text field not middle initial.",
vbExclamation, "Invalid Middle Name"
txtDetail(3).SetFocus
ElseIf txtDetail(4).Text = "" Then
MsgBox "Please, fill the address text field.", vbExclamation, "Empty
Field"
txtDetail(4).SetFocus
ElseIf Len(txtDetail(5).Text) < 11 And Len(txtDetail(5).Text) <> 0 Then
MsgBox "Invalid contact number, 7 digit number for telephone no. or
11 digit no. for mobile no.", vbExclamation, "Invalid Contact Number"
txtDetail(5).SetFocus
Else
If MsgBox("Are you sure that you want to save this record?",
vbQuestion + vbYesNo, "Save") = vbYes Then
SaveFields
.Update
MsgBox "Successfully Saved!", vbInformation, "Saved"
ConView True
Call cmdRefresh_Click
Call cmdRefresh_Click
ClearFields
txtSearch.SetFocus
End If
End If
End Select
End With
End Sub

Private Sub cmdConfirm_Click()


Dim dbTemp2 As New ADODB.Connection
Dim rsTemp2 As New ADODB.Recordset
OpenConn dbTemp2, rsTemp2, "SELECT * FROM tblTeacher WHERE na='"
& txtFull.Text & "'"
With rsTemp2
If .EOF = False Then
MsgBox "Teacher name is already exist!", vbCritical, "Exist"
txtDetail(1) = ""
txtDetail(2) = ""
txtDetail(3) = ""
txtDetail(1).SetFocus
End If
End With
CloseConn rsTemp2, dbTemp2
Timer1.Enabled = True
End Sub

Private Sub cmdRefresh_Click()


Faculty "SELECT * FROM tblTeacher WHERE Inactive=False"
ClearFields
Timer1.Enabled = False
txtSearch.Text = ""
cboSearch.Text = ""
End Sub

Private Sub cmdSearch_Click()


Select Case cboSearch.Text
Case "ID Number"
OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblTeacher WHERE
Inactive=False AND ID='" & txtSearch.Text & "'"
If rsTemp1.EOF = True Then
MsgBox "No teacher record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Faculty "SELECT * FROM tblTeacher WHERE Inactive=False"
Else
Faculty "SELECT * FROM tblTeacher WHERE Inactive=False AND
ID='" & txtSearch.Text & "'"
End If
CloseConn rsTemp1, dbTemp1

Case "Last Name"


OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblTeacher WHERE
Inactive=False AND LastName LIKE '%" & txtSearch.Text & "%'"
If rsTemp1.EOF = True Then
MsgBox "No teacher record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Faculty "SELECT * FROM tblTeacher WHERE Inactive=False"
Else
Faculty "SELECT * FROM tblTEacher WHERE Inactive=False AND
LastName LIKE '%" & txtSearch.Text & "%'"
End If
CloseConn rsTemp1, dbTemp1
Case "First Name"
OpenConn dbTemp1, rsTemp1, "SELECT * FROM tblTeacher WHERE
Inactive=False AND FirstName LIKE '%" & txtSearch.Text & "%'"
If rsTemp1.EOF = True Then
MsgBox "No teacher record found!", vbCritical, "No record"
txtSearch.Text = ""
txtSearch.SetFocus
Faculty "SELECT * FROM tblTeacher WHERE Inactive=False"
Else
Faculty "SELECT * FROM tblTeacher WHERE Inactive=False AND
FirstName LIKE '%" & txtSearch.Text & "%'"
End If
CloseConn rsTemp1, dbTemp1

Case Else
MsgBox "No current record!", vbCritical, "No record"
Call cmdRefresh_Click
End Select
End Sub

Private Sub Form_Load()


Faculty "SELECT * FROM tblTeacher WHERE Inactive=False"
OpenConn dbFaculty, rsFaculty, "SELECT * FROM tblTeacher"
Timer1.Enabled = False
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)


CloseConn rsFaculty, dbFaculty
mdiMain.tmrSidePanelShow.Enabled = True
End Sub

Private Sub Form_Resize()


MidFrm Me, mdiMain
End Sub
Private Sub lv_ItemClick(ByVal Item As MSComctlLib.ListItem)
With rsFaculty
.Requery
.Find "ID='" & Item.Text & "'"
DisplayFields
Timer1.Enabled = False
End With
End Sub
Private Sub Timer1_Timer()
Call cmdConfirm_Click
End Sub

Sub ClearFields()
txtDetail(0).Text = ""
txtDetail(1).Text = ""
txtDetail(2).Text = ""
txtDetail(3).Text = ""
txtDetail(4).Text = ""
txtDetail(5).Text = ""
txtFull.Text = ""
txtSearch.Text = ""
cboSearch.Text = ""
End Sub

Sub SaveFields()
With rsFaculty
.Fields(0) = txtDetail(0).Text
.Fields(1) = txtDetail(1).Text
.Fields(2) = txtDetail(2).Text
.Fields(3) = txtDetail(3).Text
.Fields(4) = txtDetail(4).Text
If txtDetail(5).Text = "" Then
.Fields(5) = "n/a"
Else
.Fields(5) = txtDetail(5).Text
End If
'.Fields("UserID")=id
.Fields("Date") = Date
.Fields("Time") = Time
.Fields("na") = txtFull.Text
End With
End Sub

Sub DisplayFields()
With rsFaculty
txtDetail(0).Text = .Fields(0)
txtDetail(1).Text = .Fields(1)
txtDetail(2).Text = .Fields(2)
txtDetail(3).Text = .Fields(3)
txtDetail(4).Text = .Fields(4)
txtDetail(5).Text = .Fields(5)
txtFull.Text = .Fields("na")
End With
End Sub
Private Sub txtDetail_Change(Index As Integer)
Select Case Index
Case 1
txtFull.Text = txtDetail(1).Text
Case 2
txtFull.Text = txtDetail(1).Text & ", " & txtDetail(2).Text
Case 3
txtFull.Text = txtDetail(1).Text & ", " & txtDetail(2).Text & " " &
txtDetail(3).Text
End Select
End Sub

Private Sub txtDetail_GotFocus(Index As Integer)


For Index = 0 To 5
Call high(txtDetail(Index))
Next Index
End Sub

Private Sub txtDetail_KeyPress(Index As Integer, KeyAscii As Integer)


Select Case Index
Case 1, 2, 3
If Not (KeyAscii >= 65 And KeyAscii <= 122 Or (KeyAscii = 32 Or
KeyAscii = 8)) Then
KeyAscii = 0
End If
Case 5
KeyAscii = isNumber(KeyAscii)
End Select
End Sub

Private Sub txtDetail_LostFocus(Index As Integer)


For Index = 1 To 5
txtDetail(Index).Text = Upcase(txtDetail(Index))
Next Index
End Sub

Sub ConView(ByVal visi As Boolean)


Select Case visi
Case True
For ctr = 0 To 3
cmdButton(ctr).Visible = True
Next ctr
cmdRefresh.Visible = True
cmdButton(4).Visible = False
cmdButton(5).Visible = False
picEntry.Visible = True

Case False
For ctr = 0 To 3
cmdButton(ctr).Visible = False
Next ctr
cmdRefresh.Visible = False
cmdButton(4).Visible = True
cmdButton(5).Visible = True
picEntry.Visible = False
End Select
End Sub

Private Sub txtSearch_KeyPress(KeyAscii As Integer)


Select Case cboSearch.Text
Case "ID Number"
If KeyAscii = 13 Then
Call cmdSearch_Click
End If
KeyAscii = isNumber(KeyAscii)
Case "Last Name", "First Name"
If KeyAscii = 13 Then
Call cmdSearch_Click
End If
If Not (KeyAscii >= 65 And KeyAscii <= 122 Or (KeyAscii = 32 Or KeyAscii =
8)) Then
KeyAscii = 0
End If
End Select
End Sub

frmUser

Option Explicit
Dim dbUser As New ADODB.Connection
Dim rsUser As New ADODB.Recordset
Dim dbTemp As New ADODB.Connection
Dim rsTemp As New ADODB.Recordset
Dim ctr As Integer

Sub User(ByVal strSQL As String)


Dim x
With lv.ListItems
.Clear
OpenConn dbTemp, rsTemp, strSQL
While Not rsTemp.EOF
Set x = .Add(1, , rsTemp.Fields("ID"))
x.SubItems(1) = rsTemp.Fields("LogName")
x.SubItems(2) = rsTemp.Fields("UserName")
x.SubItems(3) = rsTemp.Fields("Level")
rsTemp.MoveNext
Wend
CloseConn rsTemp, dbTemp
End With
End Sub

Private Sub cboLevel_KeyPress(KeyAscii As Integer)


KeyAscii = 0
End Sub

Private Sub cmdButton_Click(Index As Integer)


With rsUser
Select Case Index
Case 0 'Create
ConView False
.AddNew
ClearFields
txtDetail(0).Text = Format(.RecordCount, "00000")
txtDetail(1).SetFocus
cmdButton(4).Caption = "&Save"
Timer1.Enabled = True
Case 1 'Edit
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to edit.", vbExclamation, "Edit"
ElseIf txtDetail(2).Text = "Enigma" Then
MsgBox "This record cannot be edit.", vbExclamation, "Unable to edit"
Else
ConView False
cmdButton(4).Caption = "&Update"
Timer1.Enabled = False
End If
Case 2 'Delete
If txtDetail(0).Text = "" Then
MsgBox "Please, select a record to delete.", vbExclamation, "Delete"
ElseIf txtDetail(2).Text = "Enigma" Then
MsgBox "This record cannot be deleted", vbExclamation, "Unable to
delete"
Else
If MsgBox("Are you sure that you want to delete this record?",
vbQuestion + vbYesNo, "Delete") = vbYes Then
.Fields("Inactive") = True
.Update
User "SELECT * FROM tblUser WHERE Inactive=False"
User "SELECT * FROM tblUser WHERE Inactive=False"
End If
End If
Case 3 'Close
Unload Me
Case 4 'Save

If txtDetail(1).Text = "" Then


MsgBox "Please, fill login name the text field", vbExclamation, "Empty
fields"
ElseIf txtDetail(2).Text = "" Then
MsgBox "Please, fill user name the text field", vbExclamation, "Empty
fields"
ElseIf Encrypt(txtDetail(3)) <> Encrypt(txtDetail(4)) Then
MsgBox "Password did not match!", vbExclamation, "Mismatched"
ElseIf txtDetail(2).Text = txtDetail(3).Text Then
MsgBox "Don't use your user name as your password.",
vbExclamation, "Invalid password"
ElseIf Len(txtDetail(3).Text) < 4 Then
MsgBox "Password must contain atleast four (4) characters",
vbExclamation, "Invalid password"
'ElseIf .Fields("UserName") = txtDetail(2).Text Then
' MsgBox "User name is already exist!", vbExclamation, "Invalid user
name"
ElseIf cboLevel.Text = "" Then
MsgBox "Please, select a access level on the combo box",
vbExclamation, "Empty box"
Else
If MsgBox("Are you sure that you want save this record?", vbQuestion
+ vbYesNo, "Save") = vbYes Then
SaveFields
.Update
MsgBox "Successfully saved!", vbInformation, "Saved"
User "SELECT * FROM tblUser WHERE Inactive=False"
User "SELECT * FROM tblUser WHERE Inactive=False"
ConView True
lv.Visible = True
Timer1.Enabled = False
End If
End If
Case 5 'Cancel
ConView True
.CancelUpdate
ClearFields
'lv.Visible = True
Timer1.Enabled = False
End Select
End With
End Sub

Private Sub cmdConfirm_Click()


OpenConn dbTemp, rsTemp, "SELECT * FROM tblUser WHERE
UserName='" & txtDetail(2).Text & "'"
With rsTemp
If .EOF = False Then
MsgBox "User name is already exist!", vbCritical, "Exist"
txtDetail(2) = ""
txtDetail(2).SetFocus
End If
End With
CloseConn rsTemp, dbTemp
End Sub

Private Sub cmdRefresh_Click()


User "SELECT * FROM tblUser WHERE Inactive=False"
ClearFields
End Sub

Private Sub Form_Resize()


MidFrm Me, mdiMain
End Sub

Private Sub lv_ItemClick(ByVal Item As MSComctlLib.ListItem)


With rsUser
.Requery
.Find "ID='" & Item.Text & "'"
DisplayFields
Timer1.Enabled = False
End With
End Sub

Private Sub SaveFields()


With rsUser
.Fields("ID") = txtDetail(0).Text
.Fields("LogName") = txtDetail(1).Text
.Fields("UserName") = txtDetail(2).Text
.Fields("Password") = Encrypt(txtDetail(3))
.Fields("Level") = cboLevel.Text
End With
End Sub
Private Sub Form_Load()
User "SELECT * FROM tblUser WHERE Inactive=False"
OpenConn dbUser, rsUser, "SELECT * FROM tblUser"
ClearFields
Timer1.Enabled = False
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)


CloseConn rsUser, dbUser
mdiMain.tmrSidePanelShow.Enabled = True
End Sub

Private Sub ClearFields()


txtDetail(0).Text = ""
txtDetail(1).Text = ""
txtDetail(2).Text = ""
txtDetail(3).Text = ""
txtDetail(4).Text = ""
cboLevel.Text = ""
End Sub

Private Sub DisplayFields()


With rsUser
txtDetail(0).Text = .Fields(0)
txtDetail(1).Text = .Fields(1)
txtDetail(2).Text = .Fields(2)
txtDetail(3).Text = .Fields(3)
cboLevel.Text = .Fields(4)
End With
End Sub

Sub ConView(ByVal visibility As Boolean)


Select Case visibility
Case True
For ctr = 0 To 3
cmdButton(ctr).Visible = True
Next ctr
picEntry2.Visible = True
cmdButton(4).Visible = False
cmdButton(5).Visible = False
cmdRefresh.Visible = True
Case False
For ctr = 0 To 3
cmdButton(ctr).Visible = False
Next ctr
picEntry2.Visible = False
cmdButton(4).Visible = True
cmdButton(5).Visible = True
cmdRefresh.Visible = False
End Select
End Sub

Private Sub Timer1_Timer()


Call cmdConfirm_Click
End Sub

Private Sub txtDetail_GotFocus(Index As Integer)


Select Case Index
Case 0
Call high(txtDetail(0))
Case 1
Call high(txtDetail(1))
Case 2
Call high(txtDetail(2))
Case 3
Call high(txtDetail(3))
Case 4
Call high(txtDetail(4))
End Select
End Sub

Private Sub txtDetail_LostFocus(Index As Integer)


For Index = 1 To 4
txtDetail(Index).Text = Upcase(txtDetail(Index))
Next Index
End Sub

You might also like