Public CN As New ADODB.Connection
Public RS As New ADODB.Recordset
Private Sub cmdClose_Click()
CN.Close
Unload Me
End Sub
Private Sub cmdDelete_Click()
With RS
If MsgBox("Are You Sure?", vbCritical + vbYesNo, "Confirm") = vbYes Then
CN.Execute "DELETE * FROM Subjects WHERE Subject ='" & .Fields("Subject") & "'"
MsgBox "Deleted", vbInformation, "Deleted"
.Requery
End If
End With
End Sub
Private Sub cmdFirst_Click()
On Error Resume Next
With RS
.MoveFirst
If .EOF = True Then
.MoveLast
End If
txtSubject.Text = .Fields("Subject")
txtNoOfBooks.Text = .Fields("NoOfBooks")
txtDays.Text = .Fields("IssueDays")
txtFine.Text = .Fields("Finecharge")
txtReverse.Text = .Fields("ReserveCharge")
End With
End Sub
Private Sub cmdLast_Click()
On Error Resume Next
With RS
.MoveLast
If .EOF = True Then
.MoveFirst
End If
txtSubject.Text = .Fields("Subject")
txtNoOfBooks.Text = .Fields("NoOfBooks")
txtDays.Text = .Fields("IssueDays")
txtFine.Text = .Fields("Finecharge")
txtReverse.Text = .Fields("ReserveCharge")
End With
End Sub
Private Sub cmdNew_Click()
cmdSave.Enabled = True
txtSubject.Text = ""
txtNoOfBooks.Text = ""
txtDays.Text = ""
txtFine.Text = ""
txtReverse.Text = ""
RS.AddNew
End Sub
Private Sub cmdNext_Click()
On Error Resume Next
With RS
.MoveNext
If .EOF = True Then
.MoveFirst
End If
txtSubject.Text = .Fields("Subject")
txtNoOfBooks.Text = .Fields("NoOfBooks")
txtDays.Text = .Fields("IssueDays")
txtFine.Text = .Fields("Finecharge")
txtReverse.Text = .Fields("ReserveCharge")
End With
End Sub
Private Sub cmdPrevious_Click()
On Error Resume Next
With RS
.MovePrevious
If .EOF = True Then
.MoveLast
End If
txtSubject.Text = .Fields("Subject")
txtNoOfBooks.Text = .Fields("NoOfBooks")
txtDays.Text = .Fields("IssueDays")
txtFine.Text = .Fields("Finecharge")
txtReverse.Text = .Fields("ReserveCharge")
End With
End Sub
Private Sub cmdSave_Click()
With RS
If MsgBox("Are You Sure?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
If RS.EOF Then
.AddNew
End If
If txtSubject.Text <> "" And txtNoOfBooks.Text <> "" And txtDays.Text <> "" And txtFine.Text <> "" And txtReverse.Text <> "" Then
.Fields("Subject") = txtSubject.Text
.Fields("NoOfBooks") = txtNoOfBooks.Text
.Fields("IssueDays") = txtDays.Text
.Fields("FineCharge") = txtFine.Text
.Fields("ReserveCharge") = txtReverse.Text
.Update
MsgBox "Saved", vbInformation, "Saved"
End If
End If
End With
End Sub
Private Sub cmdSearch_Click()
With RS
.Close
RS.Open "Select * FROM Subjects WHERE subject ='" & txtSearch.Text & "'"
txtSearch.Text = .Fields("Subject")
.Requery
End With
End Sub
Private Sub Command1_Click()
On Error Resume Next
With RS
If MsgBox("Update The Record?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
.Fields("Subject") = txtSubject.Text
.Fields("NoOfbooks") = txtNoOfBooks.Text
.Fields("IssueDays") = txtDays.Text
.Fields("FineCharge") = txtFine.Text
.Fields("ReverseCharge") = txtReverse.Text
.Update
.Requery
MsgBox "The current record has been updated", vbInformation, "Update Successful"
End If
End With
End Sub
Private Sub Command2_Click()
If Command2.Caption = "Search" Then
Command2.Caption = "Stop"
frmSubjects.Height = 6255
Frame1.Visible = True
Else
Command2.Caption = "Search"
frmSubjects.Height = 5040
Frame1.Visible = False
End If
End Sub
Private Sub Command4_Click()
With RS
.Close
RS.Open "Select * FROM Subjects"
.Requery
End With
End Sub
Private Sub Form_Load()
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb"
RS.CursorLocation = adUseClient
RS.Open "SELECT * FROM Subjects ORDER BY Subject ASC", CN, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = RS
With RS
If Not .BOF Then
txtSubject.Text = .Fields("Subject")
txtNoOfBooks.Text = .Fields("NoOfBooks")
txtDays.Text = .Fields("IssueDays")
txtFine.Text = .Fields("Finecharge")
txtReverse.Text = .Fields("ReserveCharge")
lblStatus.Caption = "Total Records: " & CStr(RS.RecordCount)
End If
End With
DataGrid1.Columns(0).Caption = "Subject"
DataGrid1.Columns(1).Caption = "Issue Days"
DataGrid1.Columns(2).Caption = "No Of Books"
DataGrid1.Columns(3).Caption = "Fine Charge"
DataGrid1.Columns(4).Caption = "Reverse Charge"
End Sub