Library Management System using VB 6 with MS Access Database

In this post, we want to develop a library management system in visual basic 6.0 with ms access. You can visit our visual basic 6 page to learn developing other applications for your project. This project contains visual basic code for library management system using vb 6 with ms access.

Bank Management System Project in VB6 with MS Access

Employee Management System Project in VB 6 with MS Access 

Student Management System Project with VB 6 with MS Access 

You will use Microsoft Access Database as a backend to store library member information. To help you understand the project, we have included system diagram and E-R diagrams, Table design and Form design for all the database in this application.

The main activities of the library management system using vb 6 with ms access are as follows

  1. Manage member information
  2. Each member must log in using the password provided for them.

The library management system you develop must contain the following modules.

1.    frmLibraryManagement

2.    frmLogin

3.    frmBookdetails

4.    frmMemberdetails

5.    frmMenu

6.    Module.bas

System Design

 

System Diagram -Library Management System using VB 6 with MS Access

System Diagram -Library Management System using VB 6 with MS Access

Data Model – ER Diagram

The following diagram is ER diagram for library management system database with ms access.

 

ER Diagram Library Management

ER Diagram Library Management

 

Relational Model – Tables

Now we need to convert the ER Model to a Relational Model which means creating a table for each entity in the ER Model.

Book Table

The book table in Access Design View is given below. One of the Field Name is “Primary Key”, in this case, Member ID.

Book Table - Library Management System
Book Table – Library Management System

Login Table

The screenshot for the login table in Microsoft Access Design View is given below. The Field Name “User ID” is the “Primary Key” for this table”.

Login Table - Library Management System
Login Table – Library Management System

Member Table

The third table in MS Access Design View is given below. The Field Name “Member ID” is the “Primary Key” for the table.

 

Member Table - Library Management System
Member Table – Library Management System

 

Note: Primary Key is a field that uniquely identifies each row in the table.

Relationship

A Relationship is MS Access is similar to the ER Diagram we created previously. We can use the ER Diagram to create relationships between tables.

To view or create relationships among tables, go to Database Tool from the Toolbar > [Click] Relationship under Show/Hide.

 

Relationship Between Tables - Library Management System
Relationship Between Tables – Library Management System

 

The relationship between MEMBER and BOOK is called One-to-Many and the relationship between MEMBER and LOGIN is One-to-One.

 

Components for frmLibraryManagement

You can design the interface for each of the forms in Visual Basic now. However, you must rename them properly for sake of coding. Let’s create components for frmLibraryManagement as follows and rename them.

 

Form Library Management System

Form Library Management System

 

Labels

Name : lblLibraryManagement
Caption : LIBRARY MANAGEMENT SYSTEM

Buttons

Name : cmdLogin
Caption : LOGIN

Code for frmLibraryManagement

Private Sub cmdLogin_Click()

    frmLogin.Show
    Unload Me

End Sub

Components for frmLogin

The login screen is different because you want password to be hidden when you type them. To create Login dialog, {Right-Click] Project.vbp > Select Add > [Click] Form. The new form dialog box will appear, select Log in Dialog.

 

Login Dialog - Library Management System

Login Dialog – Library Management System

Now we must rename and change the code for frmLogin.

 

Form Login - Library Management System

Form Login – Library Management System

 

Labels

Name : lblUserID
Caption : User Name:
Name: lblPassword
Caption: Password

Text-Boxes

Name : txtUserID
Text: ‘leave blank’
Name : txtPassword
Text: ‘leave blank’

Buttons

Name : cmdOK
Caption: Login
Name : cmdCancel
Caption: Cancel

Code for frmLogin

Option Explicit
Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
    'set the global var to false '
    'to denote a failed login'
    LoginSucceeded = False
    Me.Hide
End Sub

Private Sub cmdOK_Click()

    rs.Open "SELECT * FROM LOGIN ", con,
    adOpenDynamic, adLockReadOnly

    While Not rs.EOF
    If rs!UserID = Val(txtUserID) Then

    'check for correct password'

    If rs!Password = txtPassword Then

    'place code to here to pass the
    'success to the calling sub
    'setting a global var is the easiest

    LoginSucceeded = True
    frmMENU.Show
    Me.Hide
    con.Close
    Exit Sub

    Else

    MsgBox "Invalid Password, try again!", , "Login"
    txtPassword.SetFocus SendKeys "{Home}+{End}"

    End If
    End If

    rs.MoveNext
    Wend

End Sub

Private Sub Form_Load()

    Call loadcon
    MsgBox ("Connected")

End Sub

Components for frmMenu – MDI form

The frmMenu is a form with menu items and we can create a menu using the Menu Editor.
To create a MDI form, [Right-Click] Project1.vbp > Select Add > [Click] MDI Form. Create following menu items using Menu Editor.

 

MDI Form with Menu - Form Book Details - Library Management System using VB 6 with MS Access

MDI Form with Menu – Form Book Details – Library Management System using VB 6 with MS Access

 

Code for frmMenu

When you click on any menu item it will open another form within the parent MDI form. The other form that must open within MDI form should have their MDI child property set to True.

 

Set MDI Child Property to True

Set MDI Child Property to True

 

Components for frmBookDetails

 

Form Book Details - Library Management System using VB 6 with MS Access

Form Book Details – Library Management System using VB 6 with MS Access

The frmBookDetails store the book information and you can perform various operations on the book database such as INSERT, DELETE, and UPDATE, etc.

Labels

Name     : lblBookDetails
Caption : BOOK DETAILS
Name     : lblBookID
Name     : lblBookname
Caption : BOOK NAME
Name     : lblAuthor
Caption : AUTHOR
Name     : lblMID
Caption : MEMBER ID

Text-Boxes

Name    : txtBookID
Text       : ‘leave blank’
Name    : txtBookname
Text       : ‘leave blank’
Name    : txtAuthor
Text       : txtAuthor
Text       : ‘leave blank’
Name    : txtMID
Text       : ‘leave blank’

Buttons

Name      : cmdAdd
Caption  : &ADD
Name      : cmdDel
Caption  : &DELETE
Name      : cmdUpdate
Caption  : &UPDATE
Name      : cmdDisplay
Caption  : &DISPLAY
Name      : cmdClear
Caption  : &CLEAR
Name      : cmdExit
Caption  : &EXIT

Data Grids

Name : DataGrid1

Code for frmBookDetails

Private Sub cmdAdd_Click()

    con.Execute "INSERT INTO BOOK (BookID, BookName,
    Author, MemberID) VALUES (" & txtBookID & ",
    '" & txtBookN & "','" & txtAuthor & "',
    " & txtMID & ")"

    MsgBox ("Record Inserted !!")

End Sub

Private Sub cmdClr_Click()

    txtBookID.Text = " "
    txtBooktitle.Text = " "
    txtAuthor.Text = " "

End Sub

Private Sub cmdDel_Click()

    con.Execute "DELETE * FROM BOOK WHERE
    BookID = " & txtBookID & ""

    MsgBox ("Record Deleted !!")

End Sub

Private Sub cmdDisplay_Click()

    rs.CursorLocation = adUseClient rs.CursorType
     = adOpenStatic rs.Open "SELECT * FROM BOOK",
    con, adOpenDynamic, adLockPessimistic

    Set DataGrid1.DataSource = rs

End Sub

Private Sub cmdExit_Click()

    Unload Me
    con.Close

End Sub

Private Sub cmdUpdate_Click()

     con.Execute "UPDATE BOOK SET BookName
     = '" & txtBookname & "', Author
     = '" & txtAuthor & "', MemberID
     = '" & txtMID & "' WHERE BOOKID
     = " & txtBID & ""

     MsgBox ("Record Updated")

End Sub

Private Sub Form_Load()

     Call loadcon MsgBox ("Connected")

End Sub

Private Sub lblBookDetails_Click()

End Sub

Components for frmMember

Form Library Members - Library Management System

Form Library Members – Library Management System

 

Labels

Name      : lblMemberDetails
Caption  : MEMBER DETAILS
Name      : lblMID
Caption  : MEMBER ID
Name      : lblMembername
Caption  : MEMBER NAME

Text-Boxes

Name      : txtMemberID
Text         : ‘leave blank’
Name      : txtMembername
Text         : ‘leave blank’

Buttons

Name      : cmdAdd
Caption  : &ADD
Name      : cmdDel
Caption  : &DELETE
Name      : cmdUpdate
Caption  : &UPDATE
Name      : cmdDisplay
Caption  : &DISPLAY
Name      : cmdClear
Caption  : &CLEAR
Name      : cmdExit
Caption  : &EXIT

Data Grids

Name : DataGrid1

Code for frmMemberDetails

Private Sub cmdAdd_Click()

    con.Execute "INSERT INTO MEMBER (MemberID, MemberName)
    VALUES (" & Text1 & ", '" & Text2 & "')"

    MsgBox ("Record Inserted")

End Sub

Private Sub cmdClr_Click()

    Text1.Text = ""
    Text2.Text = ""

End Sub

Private Sub cmdDel_Click()

    con.Execute "DELETE * FROM MEMBER WHERE
    MemberID = " & Text1 & ""

    MsgBox ("Record Deleted")

End Sub

Private Sub cmdDisplay_Click()

    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenStatic
    rs.Open "SELECT * FROM MEMBER", con,
    adOpenDynamic, adLockPessimistic

    Set DataGrid1.DataSource = rs

End Sub

Private Sub cmdExit_Click()

    Unload Me
    con.Close

End Sub

Private Sub cmdUbdate_Click()

    con.Execute "UPDATE MEMBER SET MemberID
    = " & Text1 & ", MemberName
    = '" & Text2 & "'"

    MsgBox ("Record Updated")

End Sub

Private Sub Form_Load()

    Call loadcon
    MsgBox ("Connected")

End Sub

Module1.bas

All form need to connect to Microsoft Access Database but you may have to write the code for connection in each form. It there is a large number of forms in the project, say 10, then these extra line of codes become redundant. To save us from this trouble, create Module1.bas file from Project1.vbp windows.The code for Module is given below.

Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public constr As String Public Sub loadcon()

constr = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource
=C:UsersGirishDocumentsLIBRARY.mdb;
Persist Security Info=False"

con.Open constr

Note: You cannot add the code for Module 1 because first you have to add the components for Microsoft ADO Data Control 6.0 (OLEDB) and Microsoft Data grid Control 6.0 (OLEDB).

Advertisements