You are on page 1of 15

Private Sub Form_Load()

frmLogin.Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &


"\StudentDB.mdb;Persist Security Info=False"

End Sub

Private Sub Timer1_Timer()


ProgressBar1.Value = ProgressBar1.Value + 1

Select Case ProgressBar1.Value


Case 10
Label2.Caption = "Loading..."
Case 30
Label2.Caption = "Loading Forms..."
Case 50
Label2.Caption = "Loading Database..."
Case 70
Label2.Caption = "Establishing Connection..."
Case 80
Label2.Caption = "Connection Established..."
Case 100
Label2.Caption = "Finished.."
End Select
Label3.Caption = ProgressBar1.Value & "%"
If ProgressBar1.Value = 100 Then
ProgressBar1.Value = 0
Timer1.Enabled = False
frmLogin.Show
Unload Me
End If
End Sub
Private Sub cmdCancel_Click()
Timer2.Enabled = True
End Sub

Private Sub cmdExit_Click()


Unload Me
End Sub

Private Sub cmdLogin_Click()


Adodc1.RecordSource = "SELECT * FROM tblLogin WHERE Username = '" & txtUsername.Text & "' AND
Password = '" & txtPassword.Text & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "Welcome.", vbInformation, "Login Successful"
mdiMain.Show
Unload Me
txtUsername.Text = ""
txtPassword.Text = ""
Else
MsgBox "Invalid username/password!", vbCritical, "Login Failed"
' txtUsername.Text = ""
txtPassword.Text = ""
End If
End Sub

Private Sub cmdSubmit_Click()


Adodc1.RecordSource = "SELECT * FROM tblLogin WHERE Username = '" & txtRegUsername.Text & "'"
Adodc1.Refresh

If Adodc1.Recordset.RecordCount > 0 Then


MsgBox "Username is already in use!", vbCritical, "Registration failed"
Exit Sub
Else
Dim ques As Byte
ques = MsgBox("Are you sure you want to save?", vbQuestion + vbYesNo, "Message")

If ques = vbYes Then


Adodc1.Recordset.AddNew
Adodc1.Recordset(0) = txtRegUsername.Text
Adodc1.Recordset(1) = txtRegPassword.Text
Adodc1.Recordset.Update
MsgBox "New account has been saved.", vbInformation, "Succesful"

Timer2.Enabled = True
End If
End If
End Sub

Private Sub Command1_Click()


Timer1.Enabled = True
fraLogin.Enabled = False
End Sub

Private Sub Timer1_Timer()


frmLogin.Height = frmLogin.Height + 40
If frmLogin.Height > 9785 Then
Timer1.Enabled = False
fraLogin.Enabled = False
End If
End Sub

Private Sub Timer2_Timer()


frmLogin.Height = frmLogin.Height - 40

If frmLogin.Height < 4680 Then


Timer2.Enabled = False
fraLogin.Enabled = True
End If
End Sub
Private Sub Calendar1_LostFocus()
Calendar1.Value = Date
End Sub

Private Sub cmdfrmReg_Click()


frmReg.Show
End Sub

Private Sub cmdHide_Click()


Picture2.Width = 100
End Sub

Private Sub MDIForm_Load()


lblTIme.Caption = Time
Calendar1.Value = Date
Label2.Caption = frmLogin.txtUsername.Text
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)


Dim X As Integer
X = MsgBox("Are you sure you want to exit?", vbQuestion + vbYesNo, "Message")
If X = vbYes Then
End
Else
Cancel = 1
End If
End Sub

Private Sub mnuExit_Click()


Dim X As Byte
X = MsgBox("Are you sure you want to log out?", vbQuestion + vbYesNo, "Message")
If X = vbYes Then
frmLogin.Show
Unload Me
End If
End Sub

Private Sub mnuReg_Click()


frmReg.Show
End Sub

Private Sub Timer1_Timer()


lblTIme.Caption = Time
End Sub
Dim btnClick As String

Private Sub cmdAdd_Click()

btnClick = "Add"

Call clr

fraCommands.Enabled = False

fraStud.Enabled = True

fraSrch.Enabled = False

End Sub

Private Sub cmdCancel_Click()

Call clr

cmdClear.Enabled = True

fraStud.Enabled = False
fraCommands.Enabled = True

fraSrch.Enabled = True

End Sub

Private Sub cmdClear_Click()

Call clr

End Sub

Private Sub cmdDelete_Click()

If lstStud.ListIndex = -1 Then

MsgBox "Select student record to delete from the list box --->", vbExclamation, "Error"

Exit Sub

Else

Dim X As Byte

X = MsgBox("Do you want to delete this student record?", vbYesNo + vbQuestion, "Confirm")

If X = vbYes Then

Adodc1.RecordSource = "SELECT * FROM tblStudents WHERE LRN = '" & txtLRN.Text & "'"

Adodc1.Recordset.Delete

MsgBox "Student record has been deleted.", vbInformation, "Successful"

Call Form_Load

Call clr

End If

End If

End Sub

Private Sub cmdEdit_Click()

If lstStud.ListIndex = -1 Then

MsgBox "Select record from the list box!", vbExclamation, "Error"


Exit Sub

End If

btnClick = "Edit"

fraCommands.Enabled = False

cmdClear.Enabled = False

fraStud.Enabled = True

fraSrch.Enabled = False

End Sub

Private Sub cmdExit_Click()

Unload Me

End Sub

Private Sub cmdSave_Click()

Dim X As Byte

If btnClick = "Add" Then

X = MsgBox("Do you want to save this student record?", vbYesNo + vbQuestion, "Confirm")

If X = vbYes Then

Adodc1.RecordSource = "SELECT * FROM tblStudents"

Adodc1.Refresh

With Adodc1.Recordset

.AddNew

.Fields("LRN") = txtLRN.Text

.Fields("LastName") = txtLName.Text

.Fields("MiddleName") = txtMName.Text

.Fields("FirstName") = txtFName.Text

.Fields("Gender") = cmbGender.Text

.Fields("BDate") = dtBDate.Value
.Fields("Age") = cmbAge.Text

.Fields("YearLevel") = cmbYrLevel.Text

.Fields("Section") = cmbSection.Text

.Fields("Contact") = txtContact.Text

.Fields("Address") = txtAddress.Text

.Fields("Guardian") = txtGuardian.Text

.Fields("Name") = txtLName.Text & ", " & txtFName.Text & " " & txtMName.Text

.Update

End With

Call Form_Load

Call clr

MsgBox "New student record has been saved.", vbInformation, "Successful"

End If

Else

X = MsgBox("Do you want to update this student record?", vbYesNo + vbQuestion, " Confirm")

If X = vbYes Then

Adodc1.RecordSource = "SELECT * FROM tblStudents WHERE LRN = '" & txtLRN.Text & "'"

Adodc1.Refresh

With Adodc1.Recordset

.Fields("LRN") = txtLRN.Text

.Fields("LastName") = txtLName.Text

.Fields("MiddleName") = txtMName.Text

.Fields("FirstName") = txtFName.Text

.Fields("Gender") = cmbGender.Text

.Fields("BDate") = dtBDate.Value

.Fields("Age") = cmbAge.Text

.Fields("YearLevel") = cmbYrLevel.Text

.Fields("Section") = cmbSection.Text
.Fields("Contact") = txtContact.Text

.Fields("Address") = txtAddress.Text

.Fields("Guardian") = txtGuardian.Text

.Fields("Name") = txtLName.Text & ", " & txtFName.Text & " " & txtMName.Text

.Update

End With

Call Form_Load

Call clr

Call cmdCancel_Click

MsgBox "New student record has been saved.", vbInformation, "Successful"

End If

End If

End Sub

Private Sub Form_Load()

frmReg.Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &


"\StudentDB.mdb;Persist Security Info=False"

Adodc1.RecordSource = "SELECT Name FROM tblStudents"

Adodc1.Refresh

lstStud.Clear

Do While Not (Adodc1.Recordset.EOF)

lstStud.AddItem (Adodc1.Recordset.Fields(0))

Adodc1.Recordset.MoveNext

Loop

Dim age As Byte

age = 0

'----------
Do While age <= 50

cmbAge.AddItem (age)

age = age + 1

Loop

cmbGender.AddItem ("Male")

cmbGender.AddItem ("Female")

cmbYrLevel.AddItem ("Grade 7")

cmbYrLevel.AddItem ("Grade 8")

cmbYrLevel.AddItem ("Grade 9")

cmbYrLevel.AddItem ("Grade 10")

cmbYrLevel.AddItem ("Grade 11")

cmbYrLevel.AddItem ("Grade 12")

cmbSection.AddItem ("A")

cmbSection.AddItem ("B")

cmbSection.AddItem ("C")

cmbSection.AddItem ("D")

End Sub

Private Sub clr()

txtLRN.Text = ""

txtLName.Text = ""

txtMName.Text = ""

txtFName.Text = ""

cmbGender.Text = ""

dtBDate.Value = Date
cmbAge.Text = ""

cmbYrLevel.Text = ""

cmbSection.Text = ""

txtContact.Text = ""

txtAddress.Text = ""

txtGuardian.Text = ""

End Sub

Private Sub lstStud_Click()

Adodc1.RecordSource = "SELECT * FROM tblStudents WHERE Name = '" & lstStud.Text & "'"

Adodc1.Refresh

With Adodc1.Recordset

txtLRN.Text = .Fields("LRN")

txtLName.Text = .Fields("LastName")

txtMName.Text = .Fields("MiddleName")

txtFName.Text = .Fields("FirstName")

cmbGender.Text = .Fields("Gender")

dtBDate.Value = .Fields("BDate")

cmbAge.Text = .Fields("Age")

cmbYrLevel.Text = .Fields("YearLevel")

cmbSection.Text = .Fields("Section")

txtContact.Text = .Fields("Contact")

txtAddress.Text = .Fields("Address")

txtGuardian.Text = .Fields("Guardian")

End With

End Sub

Private Sub txtFName_KeyPress(KeyAscii As Integer)


If Not ((KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 Or KeyAscii = 122)) Then

KeyAscii = 0

End If

End Sub

Private Sub txtGuardian_KeyPress(KeyAscii As Integer)

If Not ((KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 Or KeyAscii = 122)) Then

KeyAscii = 0

End Sub

Private Sub txtLName_KeyPress(KeyAscii As Integer)

If Not ((KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 Or KeyAscii = 122)) Then

KeyAscii = 0

End Sub

Private Sub txtLRN_KeyPress(KeyAscii As Integer)

If Not ((KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 8 Or KeyAscii = 27)) Then

KeyAscii = 0

End If

End Sub

Private Sub txtMName_KeyPress(KeyAscii As Integer)

If Not ((KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 Or KeyAscii = 122)) Then

KeyAscii = 0

End Sub

Private Sub txtSearch_Change()

Adodc1.RecordSource = "SELECT Name FROM tblStudents WHERE Name LIKE '" & txtSearch.Text & "%'"
Adodc1.Refresh

lstStud.Clear

Do While Not (Adodc1.Recordset.EOF)

lstStud.AddItem (Adodc1.Recordset.Fields(0))

Adodc1.Recordset.MoveNext

Loop

End Sub

You might also like