|
|
Yesterday I have shown you how to program a
simple library management system. However, its functionalities are limited
because you can only view the records from VB, you can't add, delete or save
records from the VB environment, you have to go to MS Access to do that, it is
so inconvenient. Therefore, I am going to add more functionalities to the
previous program so that you can add, save and delete records from the program
itself. Here, instead of using the navigator bar, I have added four command
buttons for browsing the database. I labeled them as First Record, Next Record,
Previous Record and Last Record. The codes associated with these buttons are as
follow:
Private Sub cmdFirst_Click()
library.Recordset.MoveFirst
End Sub
|
Private Sub cmdLast_Click()
library.Recordset.MoveLast
End Sub
|
Private Sub cmdNext_Click()
library.Recordset.MoveNext
End Sub
|
Private Sub cmdPrevious_Click()
library.Recordset.MovePrevious
End Sub
|
The
Add title, Save and Delete Commands are slightly more complicated. In order to
alert the user before he delete a record, you have to provide a pop-up
confirmation message box before he delete that record. To save the record, we
use the Update method and include all the fields that are to be upated.The codes
are as follow:
Private Sub cmdSave_Click()
library.Recordset.Fields("ISBN") = Txt_ISBN.Text
library.Recordset.Fields("Title") = Txt_Title.Text
library.Recordset.Fields("Publisher") = Txt_Publisher.Text
library.Recordset.Fields("Author") = Txt_Author.Text
library.Recordset.Fields("Year") = Txt_Year.Text
library.Recordset.Fields("Category") = Txt_Category.Text
library.Recordset.Update
End Sub
|
Private Sub cmdDelete_Click()
Dim confirm As String
confirm = MsgBox("Are you sure you want to delete this record?",
vbYesNo, "Deletion Confirmation")
If confirm = vbYes Then
library.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
Exit Sub
End Sub
|
Private Sub cmdNew_Click()
library.Recordset.AddNew
End Sub
|
|

|