library management system project code in visual basic

Upload: raman1113

Post on 14-Apr-2018

238 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/27/2019 library management system project code in visual basic

    1/51

    Submitted To: Submitted By:

  • 7/27/2019 library management system project code in visual basic

    2/51

    IndexS No. Topics Page

    1 Acknowledgment 3

    2 Tools/ Platform/ Language used &

    Hardware And Software

    Requirements

    4

    3 Project coding 5

    4 Forms 19

    5 Reports

    6 Bibliography 27

  • 7/27/2019 library management system project code in visual basic

    3/51

    Acknowledgement

    We wish to take this opportunity to express our deepest

    and immense thanks to all of the people who contributed to

    this project and helped us at every step and provided us with

    their valuable guidance.

    We want to place to record our sincere gratitude to our

    project guide Miss Parmjit Kaur, who has made us abstain

    from being hackneyed by showing us a new way and whole

    new dimensions in the analysis of our project Welcome to

    Punjab Pivot of rich culture and heritage.

    We are much obliged to our Centre head Smt.

    Simran Bagga for liberally offering the facility to complete

    our project. We would like to take this chance to express our

    heartful gratitude to Mr. Hardeep Singhwhose initiative and

    selfness helped in accomplishing this great task.

  • 7/27/2019 library management system project code in visual basic

    4/51

    Tools/ Platforms/ Languages used &

    Hardware And Software Requirements

    Platform:

    Platform which is so popular now a days i.e. Microsoft

    Windows, is used to develop this project.

    Tools:

    1. Visual Basic 6.0

    2. Microsoft Access XP

    3. Microsoft Access

    Hardware Requirements:

    1. Minimum 32 MB RAM (64 MB Recommended)

    2. Minimum 20 KB Free Space on HDD

    3.Minimum 450 MHz Processor

    Software Requirement:

    1. Windows Operating System 98/2000/XP

    2. Visual Basic 6.0

    3. Microsoft Access

  • 7/27/2019 library management system project code in visual basic

    5/51

    INTRODUCTION TO VISUAL BASIC

  • 7/27/2019 library management system project code in visual basic

    6/51

    Visual basic is very powerful and popular front-end-programming tool. Its latest versions

    have excellent features for working with the interest. It is also almost completely

    customizable through its new extensibility model. Accordingly, it has been include into

    curriculum of the course module on Post Graduation Diploma in Computer Application.

    The aim is to train the student or any working professional to write simple application

    program to meet the requirements of his organization or business.

    This course material deals with visual basic in a very systematic manner. As

    we proceed further the various features involved in the programming of visual basic are

    discussed in detail. It guide the retrieving properties and in using the various controls in

    an efficient manner. Also new version (7.0) of visual basic is more compatible and

    customized through its new extensibility model.

    The most important part that leads to an approach for connecting Visual Basic to the

    backend is data objects such as ADO, RDO and DAO. The active x data object to use this

    technique of database connectivity. Using active x programming a student gets exposed to

    one of the best approach to ward database programming.

    Microsoft Visual Basic Environment is fully integrated and supports the fully

    development life cycle. Visual Basic fully phase of the windows software Development life

    cycle, i.e. design, development and deployment visual basic provides you with a complete

    set of tools to simply rapid application development (RAD).

    Visual Basic has evolved from the original BASIC language, which is very widely used

    language. This is graphical user interface (GUI) based language, supports to windows

    programming. Existing objects are dragged and dropped into places instead of writing

    numerous lines of code.

    Visual Basic is a number of Microsoft Visual Studio, which is fully integrated suit

    of Visual tools that all have the same look and feel.

    THE PROJECT EXPLORER WINDOW

    The following section describes the different types of files and objects that you include in a

    project:-

  • 7/27/2019 library management system project code in visual basic

    7/51

    Form Module

    Form module (.frm file extension) can contain textual descriptions of the form and its

    controls, including their properties settings. They can also contain form level declarations

    of constants, variables, and external procedures; event procedures; and general procedures.

    Class Module

    Class Module(.cls file name extension) are similar to form modules, except that they

    have no visible user interface. You can use class modules to create your own object,

    including code for methods and properties.

    Standard Modules

    Standard modules (.bas file name extension) can contain public or modeled-level

    declaration of types, constants, variables, external procedures, and public procedures.

    Components

    In addition to file modules, several other types of components can be added to the

    project.

    ActiveX controls

    ActiveX controls (.ocr file name extension) are optional controls, which can be

    added to the toolbox and used on the forms. When you install Visual Basic, the

    control including with Visual Basic, the file included with Visual Basic are copied

    to a common directory (windows\system subdirectory under window 95/98).

    Additional activeX controls are available from a wide variety of sources. You can

    also create your controls using the professional or enterprises edition of Visual

    Basic.

    STRUCTURE OF A VB PROJECT

    The project file is simply a list of all the objects associated with the project, as well as

    information on the environment options you set. This information is updated every time

    you save the project. All of the files and objects can be shared by other project as well.

  • 7/27/2019 library management system project code in visual basic

    8/51

    When you have completed all the files for a project, you can convert the project into an

    executable file (.exe): From the file menu, choose the

    Make project.exe command. Each time you save a project, visual basic updates the project

    file (.vbp). A project file contains the same list of files that appears in the project explorer.

    Window, you can open an existing project file by double-clicking its icon, by choosing the

    open project command from the menu, or by dragging the file and dropping it on the

    explorer window. Project consists of

    One project file that keeps track of all the components (.vbp)

    One file for each form (.frm)

    Optionally, one file for each class module (.cls).

    Optionally, one file for each standard module (.bas)

    Optionally, one or more files containing ActiveX controls (.ocx)

    As you create, add, or remove editable files from a project, Visual Basic reflects your

    changes in the project explorer window, which contains a current list of the files in the

    project.

    Project CodingMDI Form

  • 7/27/2019 library management system project code in visual basic

    9/51

    Private Declare Function InitCommonControls Lib "comctl32.dll" () As Long

    Private Sub MDIForm_Load()

    Me.Show

    Set CN = New ADODB.Connection

    CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &

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

    If CN.State adStateOpen Then MsgBox "Could not establish a connection

    with the database" & vbNewLine & "The database should exist in

    ApplicationPath\MasterFile.mdb", vbExclamation, "Database not found!": Unload

    Me

    frmReturn.FineAmnt = CCur(GetSetting(App.Title, "Settings", "Fine Amount",

    "2"))frmReturn.MaxDays = CInt(GetSetting(App.Title, "Settings", "Max Days",

    "14"))

    End Sub

    Private Sub MDIForm_Unload(Cancel As Integer)

    Dim Form As Form

    For Each Form In Forms

    Unload Form

    Set Form = Nothing

    Next Form

    Set CN = Nothing

    End Sub

    Private Sub MDIForm_Initialize()

  • 7/27/2019 library management system project code in visual basic

    10/51

    InitCommonControls

    End Sub

    '---------------------------------------------------------------------

    '======================= Menu Coding

    ==========================

    '== Provides connectivity to other parts of the program to the user ==

    '---------------------------------------------------------------------

    Private Sub mnuAbout_Click()

    frmAbout.Show vbModal

    End Sub

    Private Sub mnuArrangeIcons_Click()

    frmMain.Arrange vbArrangeIcons

    End Sub

    Private Sub mnuBookRec_Click()

    With frmBooks

    .Show

    .SetFocus

    End With

    End Sub

  • 7/27/2019 library management system project code in visual basic

    11/51

    Private Sub mnuBookRep_Click()

    Dim RS As New ADODB.RecordSet

    RS.Open "SELECT * FROM tblBooks Order by [Book ID]", CN, adOpenStatic,

    adLockReadOnly

    Set drBookList.DataSource = RS

    drBookList.Show

    Set RS = Nothing

    End Sub

    Private Sub mnuCascade_Click()

    frmMain.Arrange vbCascade

    End Sub

    Private Sub mnuIssue_Click()

    frmIssue.Show vbModal

    End Sub

    Private Sub mnuMembers_Click()

    With frmMembers

    .Show

    .SetFocus

    End With

  • 7/27/2019 library management system project code in visual basic

    12/51

    End Sub

    Private Sub mnuReport_Click()

    Dim RS As New ADODB.RecordSet

    RS.Open "SELECT * FROM tblMembers Order by [Student ID]", CN,

    adOpenStatic, adLockReadOnly

    Set drMembers.DataSource = RS

    drMembers.Show

    Set RS = Nothing

    End Sub

    Private Sub mnuReturn_Click()

    frmReturn.Show vbModal

    End Sub

    Private Sub mnuSettings_Click()

    frmSettings.Show vbModal

    End Sub

    Private Sub mnuTileHorizontal_Click()

    frmMain.Arrange vbTileHorizontal

  • 7/27/2019 library management system project code in visual basic

    13/51

    End Sub

    Private Sub mnuTileVertical_Click()

    frmMain.Arrange vbTileVertical

    End Sub

    Private Sub mnuExit_Click()

    Unload Me

    End Sub

    Private Sub mnuUnreturnedBooks_Click()

    Dim RS As New ADODB.RecordSet

    RS.Open "SELECT tblTrans.[Book ID], tblTrans.[Student ID], tblBooks.Title,

    [First Name] & ' ' & [Middle Initial] & ' ' & [Last Name] AS Borrower, tblTrans.

    [Date Borrowed] FROM tblMembers INNER JOIN (tblBooks INNER JOIN

    tblTrans ON tblBooks.[Book ID] = tblTrans.[Book ID]) ON tblMembers.[Student

    ID] = tblTrans.[Student ID] Where (((tblTrans.Returned) = False)) ORDER BY

    tblTrans.[Book ID];", CN, adOpenStatic, adLockReadOnly

    Set drTransUn.DataSource = RS

    drTransUn.Show

    Set RS = Nothing

    End Sub

  • 7/27/2019 library management system project code in visual basic

    14/51

    Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)

    Select Case Button.Index

    Case 1: mnuIssue_Click

    Case 2: mnuReturn_Click

    Case 4: mnuBookRec_Click

    Case 5: mnuMembers_Click

    Case 6: PopupMenu mnuReports, , Toolbar1.Buttons(6).Left, Toolbar1.Top +

    Toolbar1.Height

    Case 8: mnuSettings_Click

    Case 9: mnuAbout_ClickEnd Select

    End Sub

    Add Student Form

    Option Explicit

    Private RS As ADODB.RecordSet

    Private Sub cmdOperations_Click(Index As Integer)

    'Shows the Search/Sort/Filter form by creating a new instance and destroying it once done

    Dim obj As Form

    If Index = 0 Then Set obj = frmSearch

    If Index = 1 Then Set obj = frmFilter

    If Index = 2 Then Set obj = frmSort

    With obj

    Set .SourceRs = RS

  • 7/27/2019 library management system project code in visual basic

    15/51

    .Show vbModal

    End With

    Set obj = Nothing

    End Sub

    Private Sub cmdReport_Click(Index As Integer)

    'Creates dynamic reports

    If Index = 0 Then cmdRefresh_Click

    Set drBookList.DataSource = RS

    drMembers.Show

    End Sub

    Private Sub cmdRetrive_Click()

    'Retrives a picture to be shown in the Photo box with the use of Photo Access User Control

    Dim tmpRS As New ADODB.RecordSet

    With tmpRS

    .Open "SELECT [Picture] FROM tblMembers WHERE [Student ID]='" &

    txtDisp(0).Text & "'", CN, adOpenForwardOnly, adLockOptimistic

    If Len(RS!Picture) > 0 Then

    picBox.LoadPhoto RS!Picture

    Else

    Set picBox.Picture = LoadPicture()

    End If

    .Close

    End With

    Set tmpRS = Nothing

    End Sub

  • 7/27/2019 library management system project code in visual basic

    16/51

    Private Sub Form_Load()

    'Loads a form and initializes all variables

    On Error GoTo hell

    Set RS = New ADODB.RecordSet

    RS.CursorLocation = adUseClient

    RS.Open "SELECT * FROM tblMembers", CN, adOpenDynamic, adLockOptimistic

    Set DataGrid1.DataSource = RS

    DisplayRecords

    With frmMain.ImgList32

    cmdReport(0).Picture = .ListImages(6).Picture

    cmdReport(1).Picture = .ListImages(6).Picture

    End With

    Exit Sub

    hell:

    Handler Err

    Resume Next

    End Sub

    Private Sub Form_Resize()

    'Resizes a form according to the screen size, resolution or form resize

    On Error Resume Next

    SSTab1.Height = Me.Height - 2500

    SSTab1.Width = Me.Width - 400

    Line1.X1 = SSTab1.Left

    Line1.X2 = SSTab1.Left + SSTab1.Width

    Line1.Y1 = SSTab1.Top + SSTab1.Height + 400

    Line1.Y2 = Line1.Y1

  • 7/27/2019 library management system project code in visual basic

    17/51

    DataGrid1.Width = SSTab1.Width - 280

    DataGrid1.Height = SSTab1.Height - 580

    Frame1.Height = DataGrid1.Height - 100

    Frame1.Width = DataGrid1.Width - 200

    lnBorder(0).X1 = Frame1.Left

    lnBorder(0).X2 = Frame1.Width - Frame1.Left - 180

    lnBorder(0).Y1 = txtDisp(3).Height + txtDisp(3).Top + 180

    lnBorder(0).Y2 = lnBorder(0).Y1

    lnBorder(2).X1 = lnBorder(1).X1

    lnBorder(2).X2 = lnBorder(1).X2

    lnBorder(2).Y1 = txtDisp(6).Height + txtDisp(6).Top + 180lnBorder(2).Y2 = lnBorder(2).Y1

    LineMove Line2, Line1

    LineMove lnBorder(1), lnBorder(0)

    LineMove lnBorder(3), lnBorder(2)

    picBox.Left = txtDisp(0).Left + txtDisp(0).Width + 200

    picBox.Top = txtDisp(0).Top

    picBox.Height = Frame1.Height - cmdRetrive.Height - Frame1.Top

    picBox.Width = Frame1.Width - picBox.Left - picBox.Width + txtDisp(0).Width

    cmdRetrive.Left = picBox.Left + picBox.Width - cmdRetrive.Width

    pic.Top = Line1.Y1 + 200

    Label9.Top = pic.Top

    Label11.Top = Label9.Top + Label9.Height

    Label19.Left = picBox.Left

    Label19.Top = picBox.Top - Label19.Height

    Image1.Top = pic.Top

  • 7/27/2019 library management system project code in visual basic

    18/51

    fraNavigation.Top = pic.Top

    fraNavigation.Left = Line1.X2 - fraNavigation.Width

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    'Destroys variables to free memory

    Set RS = Nothing

    Set frmMembers = Nothing

    End Sub

    Private Sub DataGrid1_KeyUp(KeyCode As Integer, Shift As Integer)

    If KeyCode = 38 Or KeyCode = 40 Then DisplayRecords

    End Sub

    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)

    DisplayRecords

    End Sub

    Private Sub DisplayRecords()

    '-Display the current and total number of record

    Dim i As Integer

    On Error Resume Next

  • 7/27/2019 library management system project code in visual basic

    19/51

    With RS

    If .RecordCount < 1 Then

    txtcount.Text = 0

    Else

    txtcount.Text = .AbsolutePosition

    End If

    lblmax.Caption = .RecordCount

    For i = 0 To 6

    txtDisp(i).Text = .Fields(i)

    Next i

    End With

    End Sub

    Private Sub cmdDelete_Click()

    'Deletes a record

    On Error GoTo hell

    With RS

    '-Check if there is no record

    If .RecordCount < 1 Then MsgBox "No record to delete.", vbExclamation: Exit Sub

    '-Confirm deletion of record

    Dim ans As Integer, pos As Integer

    ans = MsgBox("Are you sure you want to delete the selected record?", vbCritical +

    vbYesNo, "Confirm Record Deletion")

    Screen.MousePointer = vbHourglass

    If ans = vbYes Then

    '-Delete the record

    pos = .AbsolutePosition

    CN.BeginTrans

  • 7/27/2019 library management system project code in visual basic

    20/51

    .Delete

    .Requery

    CN.CommitTrans

    If pos > .RecordCount Then

    If Not .EOF Or .BOF Then .MoveFirst

    Else

    .AbsolutePosition = pos

    End If

    MsgBox "Record has been successfully deleted.", vbInformation, "Confirm"

    End If

    Screen.MousePointer = vbDefault

    End With

    Exit Sub

    hell:

    Handler Err

    CN.RollbackTrans

    End Sub

    Private Sub cmdNavigate_Click(Index As Integer)

    '

    Navigate Index, RS

    DisplayRecords

    End Sub

    Private Sub cmdRefresh_Click()

    With RS

    .Filter = adFilterNone

  • 7/27/2019 library management system project code in visual basic

    21/51

    .Requery

    End With

    End Sub

    Private Sub cmdClose_Click()

    Unload Me

    End Sub

    Private Sub cmdAMod_Click(Index As Integer)

    On Error Resume Next

    With frmMembersAE

    .AddState = Index

    .OldID = RS.Fields(0)

    If Index = 0 Then

    .txtCode.Text = RS(0)

    .txtFirst.Text = RS(1)

    .txtM.Text = RS(2)

    .txtLast.Text = RS(3)

    .cmbClass.Text = RS(4)

    .cmbSection = RS(5)

    .txtRoll = RS(6)

    End If

    .Show vbModal

    End With

    cmdRefresh_Click

    DisplayRecords

  • 7/27/2019 library management system project code in visual basic

    22/51

    End Sub

    Add Book Form

    Option Explicit

    Private RS As ADODB.RecordSet

    Private Sub Form_Load()

    'Create recordset and refresh. Link Report icons to ImageList

    On Error GoTo hell

    Set RS = New ADODB.RecordSetRS.CursorLocation = adUseClient

    RS.Open "SELECT * FROM tblBooks", CN, adOpenDynamic,

    adLockOptimistic

    Set DataGrid1.DataSource = RS

    DisplayRecords

    With frmMain.ImgList32

    cmdReport(1).Picture = .ListImages(6).Picture

    cmdReport(0).Picture = .ListImages(6).Picture

    End With

    Exit Sub

    hell:

    Handler Err

    Resume Next

    End Sub

  • 7/27/2019 library management system project code in visual basic

    23/51

    Private Sub Form_Resize()

    'Resize form to different screen sizes and resolution, also when form is resized

    On Error Resume Next

    SSTab1.Height = Me.Height - 2500

    SSTab1.Width = Me.Width - 400

    Line2.X1 = SSTab1.Left

    Line2.X2 = SSTab1.Left + SSTab1.Width

    Line2.Y1 = SSTab1.Top + SSTab1.Height + 400

    Line2.Y2 = Line2.Y1Line2.ZOrder vbBringToFront

    DataGrid1.Width = SSTab1.Width - 280

    DataGrid1.Height = SSTab1.Height - 580

    Frame1.Height = DataGrid1.Height - 100

    Frame1.Width = DataGrid1.Width - 200

    Line3.X1 = Frame1.Left

    Line3.X2 = Frame1.Width - Frame1.Left - 180

    Line3.Y1 = txtDisp(6).Height + txtDisp(6).Top + 1000

    Line3.Y2 = Line3.Y1

    LineMove Line4, Line3

    LineMove Line1, Line2

    pic.Top = Line1.Y1 + 200

    Label9.Top = pic.Top

    Label11.Top = Label9.Top + Label9.Height

  • 7/27/2019 library management system project code in visual basic

    24/51

    Image1.Top = pic.Top

    fraNavigation.Top = pic.Top

    fraNavigation.Left = Line1.X2 - fraNavigation.Width

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    'Destroy recordset and form to free memory

    Set RS = Nothing

    Set frmBooks = Nothing

    End Sub

    Private Sub cmdOperations_Click(Index As Integer)

    'Create new instances of Search/Sort/Filter forms and display them. Destroy when

    done with

    Dim obj As Form

    If Index = 0 Then Set obj = frmSearch

    If Index = 1 Then Set obj = frmFilter

    If Index = 2 Then Set obj = frmSort

    With obj

    Set .SourceRs = RS

    .Show vbModal

    End With

  • 7/27/2019 library management system project code in visual basic

    25/51

    Set obj = Nothing

    End Sub

    Private Sub cmdReport_Click(Index As Integer)

    'Create dynamic reports

    If Index = 0 Then cmdRefresh_Click

    Set drBookList.DataSource = RS

    drBookList.Show

    End Sub

    Private Sub DataGrid1_KeyUp(KeyCode As Integer, Shift As Integer)

    'Allow keyboard navigation to display recordnumber

    If KeyCode = 38 Or KeyCode = 40 Then DisplayRecords

    End Sub

    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As

    Integer)

    'Allow mouse navigation to display recordnumber

    DisplayRecords

    End Sub

  • 7/27/2019 library management system project code in visual basic

    26/51

    Private Sub DisplayRecords()

    'Display the current and total number of record

    Dim i As Integer

    On Error Resume Next

    With RS

    If .RecordCount < 1 Then

    txtcount.Text = 0

    Elsetxtcount.Text = .AbsolutePosition

    End If

    lblmax.Caption = .RecordCount

    For i = 0 To 6

    txtDisp(i).Text = .Fields(i)

    Next iEnd With

    txtDisp(5).Text = FormatCurrency$(txtDisp(5).Text)

    End Sub

    Private Sub cmdDelete_Click()

    'Deletes a record, undeletable if a book is borrowed.

    Dim ans As Integer, pos As Integer

  • 7/27/2019 library management system project code in visual basic

    27/51

    On Error GoTo hell

    With RS

    'Check if there is no record

    If .RecordCount < 1 Then MsgBox "No record to delete.", vbExclamation: Exit

    Sub

    'Check whether book is borrowed

    If .Fields("Borrowed") = True Then MsgBox "You cannot delete this book

    record because it is borrowed by someone" & vbNewLine & "The book must be

    returned to the library before its record can be deleted.", vbInformation, "Book

    Borrowed"

    'Confirm deletion of record

    ans = MsgBox("Are you sure you want to delete the selected record?",vbCritical + vbYesNo, "Confirm Record Deletion")

    Screen.MousePointer = vbHourglass

    If ans = vbYes Then

    'Delete the record

    pos = .AbsolutePosition

    CN.BeginTrans

    .Delete

    .Requery

    CN.CommitTrans

    If pos > .RecordCount Then

    If Not .EOF Or .BOF Then .MoveFirst

    Else

    .AbsolutePosition = pos

    End If

    MsgBox "Record has been successfully deleted.", vbInformation, "Confirm"

    End If

    Screen.MousePointer = vbDefault

    End With

  • 7/27/2019 library management system project code in visual basic

    28/51

    Exit Sub

    hell:

    On Error Resume Next

    Handler Err

    CN.RollbackTrans

    End Sub

    Private Sub cmdNavigate_Click(Index As Integer)

    'Navigate a recordset through command buttons

    Navigate Index, RS

    DisplayRecords

    End Sub

    Private Sub cmdRefresh_Click()

    'Refresh the recordset

    With RS

    .Filter = adFilterNone

    .Requery

    End With

    DisplayRecords

    End Sub

  • 7/27/2019 library management system project code in visual basic

    29/51

    Private Sub cmdClose_Click()

    'Close the form

    Unload Me

    End Sub

    Private Sub cmdAMod_Click(Index As Integer)

    'Open the add/edit form. Display current record values in form if modifying.

    On Error Resume Next

    With frmBooksAE

    .AddState = Index

    .OldID = RS.Fields(0)

    If Index = 0 Then

    .msdID.Text = RS.Fields(0)

    .txtTitle.Text = RS.Fields(1)

    .txtAuthor.Text = RS.Fields(2)

    .txtPublisher.Text = RS.Fields(3)

    .cmbCategory.Text = RS.Fields(4)

    .txtPrice.Text = RS.Fields(5)

    .msdISBN.Text = RS.Fields(6)

    End If

    .Show vbModal

    End With

    cmdRefresh_Click

    DisplayRecords

  • 7/27/2019 library management system project code in visual basic

    30/51

    End Sub

    ISSUE BOOK Form

    Option Explicit

    Private Sub cmdBook_Click()

    With frmSelectDg

    .CommandText = "Select * From tblBooks where Borrowed=False"

    .DataGrid1.Caption = "Members Table"

    .Show vbModal

    If .OKPressed Then

    Text5.Text = .rRS1

    Text2.Text = .rRS2

    End If

    End With

    End Sub

    Private Sub cmdCancel_Click()

    Unload Me

    End Sub

    Private Sub cmdCode_Click()

  • 7/27/2019 library management system project code in visual basic

    31/51

    Dim A As String, b As String, c As String

    With frmSelectDg

    .CommandText = "Select * From tblMembers"

    .DataGrid1.Caption = "Members Table"

    .Show vbModal

    If .OKPressed Then

    Text4.Text = .rRS1

    A = .rRS2

    b = .rRS3

    c = .rRS4

    Text1.Text = A & " " & b & " " & cEnd If

    End With

    End Sub

    Private Sub cmdIssue_Click()

    'Record that the book was taken in two places. In tblTrans, and in

    'tblBooks which will set the Borrowed Boolean to True.

    Dim RS As ADODB.RecordSet

    If Text4.Text = "" Then Text4.SetFocus: Exit Sub

    If Text5.Text = "" Then Text5.SetFocus: Exit Sub

    On Error GoTo hell

    CN.BeginTrans

    Set RS = New ADODB.RecordSet

    With RS

  • 7/27/2019 library management system project code in visual basic

    32/51

    .Open "Select * from tblTrans", CN, adOpenDynamic, adLockOptimistic

    .AddNew

    .Fields(0) = Text5.Text

    .Fields(1) = Text4.Text

    .Fields(2) = Date

    .Update

    .Close

    .Open "Select [Borrowed] from tblBooks where [Book ID]='" & Text5.Text &

    "'", CN, adOpenDynamic, adLockOptimistic

    .MoveFirst

    .Fields(0) = True

    .Update

    .Close

    Set RS = Nothing

    End With

    CN.CommitTrans

    If MsgBox("The book " & Text5.Text & " has been issued to " & Text4.Text &

    vbNewLine & "Do you want to create a new issue instance?", vbInformation +vbYesNo) = vbYes Then

    cmdReset_Click

    Else

    Unload Me

    End If

    Exit Sub

    hell:

    Handler Err

    CN.RollbackTrans

  • 7/27/2019 library management system project code in visual basic

    33/51

    End Sub

    Private Sub cmdReset_Click()

    Text1.Text = ""

    Text2.Text = ""

    Text5.Text = ""

    Text4.Text = ""

    Text3.Text = FormatDateTime$(Date, vbLongDate)

    Text6.Text = FormatDateTime$(Date + frmReturn.MaxDays, vbLongDate)

    End Sub

    Private Sub Form_Load()

    cmdReset_Click

    With frmMain

    cmdCode.Picture = .ImgList16.ListImages(1).PictureMe.Icon = .ImgList32.ListImages(7).Picture

    End With

    cmdBook.Picture = cmdCode.Picture

    Image1.Picture = Me.Icon

    End Sub

    Private Sub Text4_Keypress(Keyascii As Integer)

    cmdCode_Click

  • 7/27/2019 library management system project code in visual basic

    34/51

    End Sub

    Private Sub Text5_KeyPress(Keyascii As Integer)

    cmdBook_Click

    End Sub

    RETURN BOOK Form

    Option Explicit

    Public MaxDays As Integer

    Public FineAmnt As Currency

    Private Sub cmdCancel_Click()

    Unload Me

    End Sub

    Private Sub cmdReset_Click()

    lblLate.Caption = "Select a book first"

    lblFines.Caption = "Select a book first"

    lblDate.Caption = "Select a book first"

    txtFines.Text = ""

    txtFines.Locked = True

    Text1.Text = ""

    Text4.Text = ""

  • 7/27/2019 library management system project code in visual basic

    35/51

    Text2.Text = FormatDateTime$(Date, vbLongDate)

    End Sub

    Private Sub cmdReturn_Click()

    Dim RS As ADODB.RecordSet

    If Text4.Text = "" Then Text4.SetFocus

    On Error GoTo hell

    Set RS = New ADODB.RecordSetWith RS

    CN.BeginTrans 'Begin a new transaction

    .Open "Select [Borrowed] from tblBooks where [Book ID]='" & Text4.Text & "'",

    CN, adOpenDynamic, adLockOptimistic

    .MoveFirst

    .Fields(0) = False

    .Update

    .Close

    .Open "Select [Fines],[Returned] From tblTrans where [Book ID]='" & Text4.Text &

    "'" & "And [Returned] = False", CN, adOpenDynamic, adLockOptimistic

    .MoveFirst

    .Fields("Fines") = CCur(txtFines.Text)

    .Fields("Returned") = True

    .Update

    .Close

    CN.CommitTrans 'If no error was raised then record info

    End With

    Set RS = Nothing

  • 7/27/2019 library management system project code in visual basic

    36/51

    'Show MsgBox if another book needs returning

    If MsgBox("The book " & Text4.Text & " has been returned from " & Text1.Text &

    vbNewLine & vbNewLine & "Do you want to create a new return book instance?",

    vbInformation + vbYesNo) = vbYes Then

    cmdReset_Click

    Else

    Unload Me

    End If

    Exit Sub

    hell:Handler Err

    On Error Resume Next 'If an error was raised then rollback

    CN.RollbackTrans 'any transaction so GIGO does not take place

    'in the future.

    End Sub

    Private Sub cmdCode_Click()

    Dim RS As ADODB.RecordSet, i As Integer

    'The first part of this event procedure will open the frmSelectDg form

    'and expect an input from the user. This will ease the selection part

    'from the users point-of-view and validation part from the devolopers

    'point-of-view.

    On Error Resume Next

    With frmSelectDg

  • 7/27/2019 library management system project code in visual basic

    37/51

    'First show the box

    .CommandText = "SELECT tblTrans.[Book ID], tblTrans.[Student ID],

    tblBooks.Title, [First Name] & ' ' & [Middle Initial] & ' ' & [Last Name] AS Borrower,

    tblTrans.[Date Borrowed] FROM tblMembers INNER JOIN (tblBooks INNER JOIN

    tblTrans ON tblBooks.[Book ID] = tblTrans.[Book ID]) ON tblMembers.[Student ID] =

    tblTrans.[Student ID] Where (((tblTrans.Returned) = False)) ORDER BY tblTrans.[Book

    ID];"

    .DataGrid1.Caption = "Members Table"

    .Show vbModal

    'Now display the data

    If .OKPressed Then

    Text4.Text = .rRS1Text1.Text = .rRS2

    txtFines.Locked = False

    Else

    'If the user did not enter anything then skip the second

    'part of the procedure to skip errors that may arise because

    'there will be no data (in text4 and text1) and as such

    'null errors or record not found errors.

    Exit Sub

    End If

    End With

    'The second part will calculate the number of days a book was taken out

    'of the library and print it in the txtFines text box.

    Set RS = New ADODB.RecordSet

    RS.Open "Select * from tblTrans Where [Book ID] ='" & Text4.Text & "'", CN,

    adOpenDynamic, adLockOptimistic

    lblDate.Caption = CDate(RS(2)) 'Just for validation

  • 7/27/2019 library management system project code in visual basic

    38/51

    'Store the difference of the current date and the date returned

    'in a variable. It the variable is negative it means that the

    'book returned is within the time limit and Fines=i*FineAmnt

    'must be 0. So transform i into 0

    i = Date - CDate(lblDate.Caption)

    If i < 0 Then i = 0

    If MaxDays < i Then lblLate.Caption = i - MaxDays Else lblLate.Caption = "0"

    'Print fines due in a label and a text box

    lblFines.Caption = CStr(FormatCurrency$(FineAmnt * lblLate))

    'Also, use an editable text box so the correct amount a member

    'is payed is recorded. Sometimes the member may pay money not'exactly as required (payable $15 from $15.25 total fines)

    txtFines.Text = lblFines.Caption

    Set RS = Nothing

    'So, practically all the librarian did was just select a book id through

    'a GUI friendly interface and everything will be done by the system

    End Sub

    Private Sub Command4_Click()

    On Error GoTo hell

    Shell "calc.exe", vbNormalFocus

    Exit Sub

    hell:

    MsgBox "The operating system cannot find the system calculator." & vbNewLine &

    "Please check whether it is properly installed or not", vbCritical, "File not found"

  • 7/27/2019 library management system project code in visual basic

    39/51

    End Sub

    Private Sub Form_Load()

    Me.Icon = frmMain.ImgList32.ListImages(8).Picture

    Image1.Picture = Me.Icon

    cmdReset_Click

    cmdCode.Picture = frmMain.ImgList16.ListImages(1).Picture

    End Sub

    Private Sub Text4_Keypress(Keyascii As Integer)

    cmdCode_Click

    End Sub

    Search FormOption Explicit

    Public SourceRs As ADODB.RecordSet

    Private AlreadyFilled As Boolean

    Private AlreadySearched As Boolean

    Private CurrPos As Long

    Private oldpos As Long

    Private Sub Combo1_KeyPress(Keyascii As Integer)

    Keyascii = 0

  • 7/27/2019 library management system project code in visual basic

    40/51

    End Sub

    Private Sub Command1_Click()

    On Error GoTo Err

    If Text1.Text = "" Then Text1.SetFocus: Exit Sub

    If Combo1.Text = "" Then Combo1.SetFocus: Exit Sub

    With SourceRs

    If AlreadySearched = False Then

    oldpos = .AbsolutePosition

    .MoveFirst

    .Find "[" & Combo1.Text & "] like *" & Text1.Text & "*"CurrPos = .AbsolutePosition

    If .EOF Then

    MsgBox "Could not find '" & Text1.Text & "' in '" & Combo1.Text & "'.",

    vbExclamation

    .AbsolutePosition = oldpos

    Else

    AlreadySearched = True

    Command1.Caption = "Search Next"

    End If

    Else

    oldpos = .AbsolutePosition

    .MoveNext

    .Find "[" & Combo1.Text & "] like *" & Text1.Text & "*"

    CurrPos = .AbsolutePosition

    If .EOF Then MsgBox "Search completed.", vbInformation: AlreadySearched =

    False: .AbsolutePosition = oldpos

    End If

    End With

  • 7/27/2019 library management system project code in visual basic

    41/51

    Exit Sub

    Err:

    If Err.Number = -2147217881 Then Search_Number: Resume Next

    If Err.Number = 3265 Then MsgBox "Please select a valid section from the list",

    vbExclamation: HighLight Text1: Exit Sub

    Handler Err

    End Sub

    Private Sub Search_Number()

    'For Number data type

    On Error GoTo Err

    SourceRs.Find "[" & Combo1.Text & "] like " & Text1.Text & ""

    Exit Sub

    Err:

    Search_DateTime

    End Sub

    Private Sub Search_DateTime()

    'For Date/Time data type

    On Error GoTo Err

    SourceRs.Find "[" & Combo1.Text & "] like #" & Text1.Text & "#"

    Exit Sub

  • 7/27/2019 library management system project code in visual basic

    42/51

    Err:

    MsgBox "Please enter an appropriate value that correspand" & vbCrLf & "where to find

    it (ex.Search for 10/23/1985 and Look in Date).", vbExclamation

    End Sub

    Private Sub Command2_Click()

    Unload Me

    End Sub

    Private Sub Form_Load()

    FillCombo Combo1, SourceRs, False

    Me.Icon = Image1.Picture

    Combo1.ListIndex = 0

    End Sub

    Private Sub Text1_Change()

    AlreadySearched = False

    End Sub

  • 7/27/2019 library management system project code in visual basic

    43/51

    Forms

    (MDI) Form

  • 7/27/2019 library management system project code in visual basic

    44/51

    Add Member Form

  • 7/27/2019 library management system project code in visual basic

    45/51

    Add Book Form

  • 7/27/2019 library management system project code in visual basic

    46/51

    BOOK ISSUE FORM

  • 7/27/2019 library management system project code in visual basic

    47/51

    BOOKS RETURN FORM

  • 7/27/2019 library management system project code in visual basic

    48/51

    REPORTS

    LIST OF BOOKS REPORT

  • 7/27/2019 library management system project code in visual basic

    49/51

    LIST OF MEMBERS REPORT

  • 7/27/2019 library management system project code in visual basic

    50/51

    LIST OF BOOKS UN RETURNED

  • 7/27/2019 library management system project code in visual basic

    51/51

    Bibliography

    1. Evangels Petrotsos

    Mastering Visual Basic 6,

    BPB Publications

    2. Content Development Group

    Visual Basic 6.0 Programming

    Tata McGraw Hill

    3. Siler Spotls

    Special Edition Using Visual Basic 6

    Prentice-Hall India

    4. Visual Basic Programming Bible

    Wiley Sons India Ltd.

    5. Complete reference to MS-ACCESS

    Tata McGraw Hill

    6. Silberschatz , Karth & Sudarshann

    Database System Concepts

    Tata McGraw Hill

    7. Elmasri, Navathe

    Fundamentals of Database System

    Low Price Edition.