Unit 5 Ms Access

Embed Size (px)

Citation preview

  • 7/30/2019 Unit 5 Ms Access

    1/28

    UNIT 5 INTRODUCTION TO MS ACCESS

    Structure

    5.0 Objectives

    5.1 Introduction5.2 MS Access Interface

    5.3 Screen Layouts

    5.4 Getting Started with MS Access

    5.5 Database Objects: Tables

    5.6 Database Objects : Queries

    5.7 Data Objects : Forms

    5.8 Data Objects : Reports

    5.9 Macros and Modules5.10 Summary

    5.11 Answers to Self Check Exercises

    5.12 Keywords

    5.13 References and Further Reading

    5.0 OBJECTIVES

    You have learned the basic concepts of DBMS in the previous Unit. In this

    Unit you will be able to learn MS Access a DBMS software package. This

    will provide you an opportunity to know how a DBMS works and how it can

    be used to suit different requirements.

    After the completion of this unit, you will be able to:

    learn the basic concepts of MS-Access;

    learn to create a database in MS-Access;

    create the various database objects like tables, queries, forms, reports;

    and

    learn about macros and modules.

    5.1 INTRODUCTION

    A database is a collection of data related to a particular topic or purpose (e.g.,

    a phone book or an address file). Microsoft Access is a relational database

    management system used on desktop computers to manage information on

    different levels for different purposes (See Block-1, Unit-4 of this course). It

    is a powerful package used for creating and managing databases. It has certain

    built-in features which assist in construction and viewing of information.

    Using Microsoft Access, one can manage information from a single databasefile. Within the file, one can use:

    Tables to store data.80

  • 7/30/2019 Unit 5 Ms Access

    2/28

    81

    Introduction to MS Access Queries to find and retrieve the data that is required.

    Forms to view, add, and update data in tables.

    Reports to analyse or print data in a specific layout.

    Dataaccess pages to view, update, or analyse the databases data from

    the Internet or an intranet.

    In Access, the database information is stored in the form of data tables. Every

    table has a structure that provides the facility for the collection, organisation,

    storage, and retrieval of data. These tables are contained in a database file.

    Each database file can have numerous data tables.

    A data table consists offields and records. Fields are categories of information,

    such as name or phone number. A group of related fields (for example, one

    persons name, address, and phone number) is called a record. In tables, fields

    are displayed as columns and records are displayed as rows.

    Tables are the basic objects in Access, but there are other objects also that

    allow data to be retrieved, viewed, manipulated, and reported. The following

    table describes the other Access objects.

    Table 1: Various objects in Access

    Object Object Type

    Table

    This object type

    multiple records

    entered, edited, s

    Query

    A way of requ

    query, a selected

    edit or print the

    Form

    Through a scree

    Forms allow yo

    alternative to dis

    A design for pri

    For a thorough knowledge of how MS Access works it is important to

    understand the hierarchy of a database in Access.

  • 7/30/2019 Unit 5 Ms Access

    3/28

    82

    Database Concepts

    Database File

    Table

    Field

    Data type

    Value

    Fig. 5.1: Hierarchy of database in MS Access

    (Source: PGDLAN, Block-1)

    5.2 MS ACCESS INTERFACE

    The top most section of the MS Access interface is the title bar comprising the

    system icon, title bar area and the windows system buttons.1

    3

    Title

    Fig. 5.2: MS Access Interface

    The menu bar is just below the title bar comprising the following tabs:

    Database File is the main file that

    covers the entire database that can be

    saved in the hard drive or any other

    storage device. The extension for this

    file is .mdb

    Table is a collection of data on a spe-

    cific aspect. A database may contain

    multiple tables viz. data on books,

    users, vendors etc. in a library.

    Fields are different categories within a

    table. For instance in a table for books

    in a library, fields like author name,

    title, publisher etc. are required.

    Value is the element entered for each

    field for instance a particular authors

    surname.

    Data types are the properties of each

    field which could be a text (numbers,

    letters and punctuation), number (even

    decimal points) or date (data on date

    and time).

  • 7/30/2019 Unit 5 Ms Access

    4/28

    83

    Introduction to MS AccessFile- This provides the options to open, close, create new,

    save, print, send, recently opened databases and exit.

    Fig. 5.3: File Menu

    Edit- This menu provides functions like cut, copy, paste and delete.

    Fig. 5.4: Edit Menu

    View- This menu provides options to view different

    database objects (tables, queries, forms, reports), make the

    icons small or large, toolbars etc.

    Fig. 5.5: View Menu

    Insert- This menu provides options to insert a new

    Table, Query, Form, Report etc. this menu may be used.

    Fig. 5.6: Insert Menu

    Tools- This menu button provides a variety of tools to

    check spelling, provide relationship between tables,

    perform analysis etc.

    Fig. 5.7: Tools Menu

  • 7/30/2019 Unit 5 Ms Access

    5/28

    84

    Database Concepts Window- This Menu provides options to arrange

    the access window orizontally, vertically or cascade,

    also shows list of recently opened databases.

    Fig. 5.8: Window Menu

    Help- This menu provides help on Access. One can

    search through the help topics with the index.

    Fig. 5.9: Help Menu

    5.3 SCREEN LAYOUTS

    Database Window

    The Database Window organises all of the objects in the database. The default

    tables listing provides links for creating tables and will list all the tables in the

    database when they have been added.

    Fig. 5.10: Database Window

    Design View

    Design View customises the fields in the database so that data can be entered.

  • 7/30/2019 Unit 5 Ms Access

    6/28

    85

    Introduction to MS Access

    Fig. 5.11: Design ViewDatasheet View

    The datasheet allows you to enter data into the database.

    Fig. 5.12: Datasheet View

    5.4 GETTING STARTED WITH MS ACCESS

    The Microsoft Access can be opened by using any of the following methods:

    1) Double clicking the MS Access icon on the desktop.

    Fig. 5.13: MS Access Icon on the Desktop

  • 7/30/2019 Unit 5 Ms Access

    7/28

    86

    Database Concepts2) Click on start button . Then go to programs and select Microsoft

    Access (Fig. 5.14).

    Fig. 5.14: MS Access Option under Programs

    When you open Access a dialogue box opens (as shown in Fig. 5.15) which

    gives the following options:

    Create a New Database from scratch

    Use the wizard to create a New Database

    Open an existing database

    Student databaseExpert list

    Fig. 5.15: MS Access Dialogue box

    Open an existing Database

    The white box shows the most recent databases you have used. If you do not

    see the one you had created, choose the More Files option and click OK.Otherwise choose the database you had previously used and click OK.

    Create a database using the Database Wizard

    1) When Microsoft Access first starts up, a dialog box is automatically

    displayed with options to create a new database or open an existing one.

    If this dialog box is displayed, clickAccess Database Wizards, pages,

    and projects and then click OK.

    If you have already opened a database or closed the dialog box that displays

    when Microsoft Access starts up, click New Database on the toolbar.

    2) On the Databases tab, double-click the icon for the kind of database youwant to create.

    3) Specify a name and location for the database.

  • 7/30/2019 Unit 5 Ms Access

    8/28

    87

    Introduction to MS Access4) Click Create to start defining your new database.

    Create a database without using the Database Wizard

    When Microsoft Access first starts up, a dialog box is automatically

    displayed with options to create a new database or open an existing one.

    If this dialog box is displayed, click Blank Access Database and then

    click OK.If you have already opened a database or closed the dialog box that displays

    when Microsoft Access starts up, click New Database on the toolbar,

    and then double-click the Blank Database icon on the General tab.

    Specify a name and location for the database and click Create. (Below is

    the screen that shows up this step).

    Fig. 5.16: Database Window

    5.5 DATABASE OBJECTS: TABLES

    Tabs for the main database Window provide the following options:

    Tables (tables available in the database)

    Queries (any queries saved in the database)

    Forms ( forms saved in the database)

    Reports ( reports saved in the database)

    Macros (any short program saved in the database)

    Modules (Visual basic for application procedures stored in the database)

    Tables

    Tables are grids that store information in a database. A table is a collection of

    data on a specific aspect viz. student records, user information etc. In tables

    data are organised in rows and columns. Each row represents a particular record

    and a column represents a particular field.

    Table 2: Table having 3 Rows and 5 Columns

  • 7/30/2019 Unit 5 Ms Access

    9/28

    88

    Database Concepts Access provides three ways to create a table for which there are icons in the

    Database Window. Double-click on the icons to create a table. In Access,

    tables can be created either through the help of wizard or through the design

    view option.

    Fig. 5.17: The Database Window

    Create table in Design view will allow you to create the fields of the

    table. This is the most common way of creating a table and is explained in

    detail below.

    Create table using wizard will lead you step-by-step through the creation

    of a table.

    Create table by entering data will give you a blank datasheet with

    unlabelled columns. Enter data into the cells and click the Save button.

    You will be prompted to add a primary key field. After the table is saved,

    the empty cells of the datasheet are trimmed. The fields are given genericnames such as Field1, Field2, etc. To rename them with more

    descriptive titles that reflect the content of the fields, select

    Format|Rename Column from the menu bar or highlight the column,

    right-click on it with the mouse, and select Rename Column from the

    shortcut menu.

    Let us see how a table is created from scratch.

    Click the New button, then highlight the Design View button in the dialogue

    box that

    appears and click the OKbutton.

    Fig. 5.18: Creating a New Table

  • 7/30/2019 Unit 5 Ms Access

    10/28

    89

    Introduction to MS Access In the Table Design view fill in the Field Name, Data Type, and

    Description for each field as shown in the figure.

    Fig. 5.19: Table Design view

    After filling in all the field it is important to define the primary key. Primary

    Key uniquely identifies the records in the table. In this example(Fig. 5.20)

    User ID has been selected as the Primary Key. For this, click the right

    mouse button on the User ID field and choose Primary Key from the pop-

    up menu that appears. A small key will appear next to the field name on

    the left side indicating that it is the primary key.

    Fig. 5.20: Defining a Primary Key

    Save the table after this. In the File menu choose Save, a dialogue box

    will appear in which type the name of the new table (Fig. 5.21). By default

    it gives names like Access Table 1, Table 2 etc. Simply overwrite this

    with a new name.

  • 7/30/2019 Unit 5 Ms Access

    11/28

    90

    Database Concepts

    Fig. 5.21: Defining the Name of the Table

    Create table using wizard

    Access table wizard will guide you in creating a table.

    Click the create table by using wizard icon in the database window to

    create a table with the help of wizard.

    A new screen will appear as shown in Fig. 5.22 . Select the fields that are

    required in the table. After selecting the required fields click Next.

    Fig. 5.22: Select Fields for the Table

    On the next screen, enter the name for the table and click Finish (Fig.

    5.23).

    Fig. 5.23: Naming the Table

  • 7/30/2019 Unit 5 Ms Access

    12/28

    91

    Introduction to MS Access After this you may select options for inputting data into the table (Fig.

    5.24).

    Fig. 5.24: Options for Entering Data into the Table

    After defining the table the next step is to add data in the table. Data can

    be added, deleted or modified in tables using the spread sheet like interface.

    Fill in the records with all fields as shown in the Fig. 5.25. Save the new

    data by pulling down the File menu and then choosing Save button.

    Fig. 5.25: Adding Data in a Table

    To navigate to other records in the table, use the navigation bar at the bottom

    of the screen.

    For modifying existing data, navigate to the record to be modified and tab to

    the appropriate field. Use the arrow keys and the delete or backspace keys to

    change the existing data. To delete a record, first navigate to the particular

    record then pull down the Edit menu and choose the Delete menu item.

  • 7/30/2019 Unit 5 Ms Access

    13/28

    92

    Database Concepts5.6 DATABASE OBJECTS: QUERIES

    Queries facilitate fast retrieval and display of data from tables. This is very

    useful when tables are very large. Queries can be used to retrieve information

    from a single table or multiple tables. Queries select records from one or more

    tables in a database so that they can be viewed, analysed, and sorted on acommon datasheet. Queries help in limiting the data in a table for specific

    goal. For instance in a user database we may require information about the

    users name and user id. Like tables, queries are managed from the Database

    Window under the menu tab.

    Fig. 5.26: Query

    Creating a query can be accomplished by using either the query design view

    or the Query wizard.

    Create a Query in Design View

    Follow these steps to create a new query in Design View:

    From the Queries page on the Database Window, click the New button.

    Fig. 5.27: Queries page on the Database Window

    New

    Design

    View

  • 7/30/2019 Unit 5 Ms Access

    14/28

    93

    Introduction to MS Access Select Design View and click OK(Fig. 5.27).

    Select tables and existing queries from the Tables and Queries tabs and

    click theAdd button to add each one to the new query (Fig. 5.28).

    Click Close when all of the tables and queries have been selected.

    Fig. 5.28: Selecting Table and Existing Queries

    Add fields from the tables to the new query by double-clicking the field

    name in the table boxes or selecting the field from the Field: and Table:

    drop-down menus on the query form (Fig. 5.29). Specify sort orders if

    necessary i.e., you can specify the order in which the records are displayed.

    Field row shows the name of the fields included in the query.

    Table row shows the name of the table that the field comes from.Sort row allows you to specify the order in which the records are

    displayed.

    Criteria row allows you to specify criteria for including or excluding

    records from the results set.

    Fig. 5.29: Query Form

    Field RowTable Row

    Sort Row

    Criteria Row

  • 7/30/2019 Unit 5 Ms Access

    15/28

    94

    Database Concepts Enter the criteria for the query in the Criteria: field. Table provides

    examples for some of the wildcard symbols and arithmetic operators that

    may be used. The Expression Builder can also be used to assist in

    writing the expressions.

    Table 3: Query Wildcards and Expression Operators

    After you have selected all of the fields and tables, click the Run button

    on the toolbar.

    Save the query by clicking the Save button.

    Query Wizard

    Access Query Wizard will easily assist you to begin creating a select query.

    Click the Create query by using wizard icon in the database window to

    have Access step you through the process of creating a query.

    Fig. 5.30: Access Query Wizard

    From the first window (Fig. 5.30), select fields that will be included in

    the query by first selecting the table from the drop-down Tables/Queries

    Wildcard /

    Operator

    ? The q

    a sing

    * The acharac

    =1 Value"INDIA" Not eBetween 1 and 10

    NumbIs Null

    Is Not Null Findsor allLike "R*" All w

    Table/Queries

    > Button

    >> Button

  • 7/30/2019 Unit 5 Ms Access

    16/28

    95

    Introduction to MS Accessmenu. Select the fields by clicking the single arrow> button to move the

    field from the Available Fields list to Selected Fields. Click the double

    arrow button >> to move all of the fields to Selected Fields. Select another

    table or query to choose from more fields and repeat the process of moving

    them to the Selected Fields box. Click Next button when all of the fields

    have been selected.

    Fig. 5.31: Entering Name for the Query

    On the next window, enter the name for the query and click Finish (Fig.

    5.31).

    Finding Duplicate Query

    This query will filter out records in a single table that contain duplicate values

    in a field.

    Click the New button on the Queries database window, select Find

    Duplicates Query Wizard from the New Query window and click OK

    (Fig. 5.32).

    Fig. 5.32: find Duplicates Query Wizard

    Select the table or query that the Find Duplicates Query will be appliedto from the list provided and click Next button (Fig. 5.33).

  • 7/30/2019 Unit 5 Ms Access

    17/28

    96

    Database Concepts

    Fig. 5.33: Selecting Table or Query for Duplicate Query

    Select the fields that may contain duplicate values by highlighting the

    names in theAvailable fields list and clicking the > button to individually

    move the fields to the Duplicate-value fields list or >> to move all of the

    fields. Click Next button when all fields have been selected (Fig. 5.34).

    Fig. 5.34: Selecting Fields with Duplicate Value

    Select the fields that should appear in the new query along with the fields

    selected on the previous screen and click Next button.(Fig. 5.35)

    Fig. 5.35: Selecting Additional Fields

    Table or Quer

  • 7/30/2019 Unit 5 Ms Access

    18/28

    97

    Introduction to MS Access Name the new query and click Finish(Fig. 5.36).

    Fig. 5.36: Naming the New Query

    Delete a Query

    To delete a table from the query, click the tables title bar and press the Delete

    key on the keyboard.

    Self Check Exercise

    1) Give a brief description of queries.

    Note: i) Write your answer in the space given below.

    ii) Check your answer with the answers given at the end of this Unit.

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    5.7 DATA OBJECTS: FORMS

    Forms

    Forms are windows objects used to view and/or enter data in the database.They offer more user-friendly interface by adding labels for each field and

    other helpful information. A form can combine data from one or more tables

    or queries. Forms can be created by hand using a Design View or through

    wizards.

    Forms can have different layouts or arrangement based on the labels and fields

    on the screen:

    Columnar - Labels are placed to the left of each field. Most suitable for

    viewing data is one record at a time.

    Tabular - Field labels are placed at the top of the screen and the recordsare displayed below like a spreadsheet. Most suitable for displaying

    multiple records is of data at a time.

  • 7/30/2019 Unit 5 Ms Access

    19/28

    98

    Database Concepts Datasheet - Data appears in the similar fashion as viewing or adding data

    to a table.

    Justified - Labels are placed above each field with the fields spread out

    on the form. This is suitable for viewing a single record.

    Forms are used as an alternative way to enter data into a database table.

    Create Form by Using Wizard

    To create a form using the assistance of the wizard, follow these steps:

    Click the Create form by using wizard option on the database window.

    A new screen will appear as shown in Fig. 5.37. From the Tables/Queries

    drop-down menu, select the table or query whose datasheet the form is

    required to modify. Then, select the fields that will be included on the

    form by highlighting each one of theAvailable Fieldswindow and clicking

    the single right arrow button > to move the field to the Selected Fields

    window. To move all of the fields to Select Fields, click the double right

    arrow button >>. If you make a mistake and would like to remove a field

    or all of the fields from the Selected Fields window, click the left arrow to move fields one at

    a time or the double arrow button >> to move all of the fields at once.

    Click the Next button to move to the next screen.

    Fig. 5.45: MS-Access Report Wizard

    Select fields from the list in which the records should be grouped by and

    click the right arrow button > to add those fields to the diagram (Fig.

    5.46). Use the Priority buttons to change the order of the grouped fields

    if more than one field is selected. Click Next > to continue.

    Fig. 5.46: Select Fields Required in the Report

    If the records should be sorted, identify a sort order here (Fig. 5.47). Select

    the first field by which records should be sorted by and click the A-Z sort

    button to choose from ascending or descending order. Click Next to

    continue.

  • 7/30/2019 Unit 5 Ms Access

    24/28

    103

    Introduction to MS Access

    Fig. 5.47: Select the Sort Order

    Select a layout and page orientation for the report and click Next (Fig.

    5.48).

    Fig. 5.48: Select A Layout and Page Orientation

    Select a colour and graphics style for the report and click Next (Fig. 5.49).

    Fig. 5.49: Select Colour and Graphics Style

    On the final screen, name the report and select to open it in either Print

    Preview or Design View mode (Fig. 5.50). Click the Finish button tocreate the report.

  • 7/30/2019 Unit 5 Ms Access

    25/28

    104

    Database Concepts

    Fig. 5.50: Give the Title For the Report

    Create in Design View

    To create a report from scratch, select Design View from the Reports Database

    Window.

    Click the New button on the Reports Database Window (Fig. 5.51).

    Highlight Design View and choose the data source of the report from

    the drop-down menu and click OK.

    Fig. 5.51: Creating Report in Design View

    You will be presented with a blank grid with a Field Box and form element

    toolbar that looks similar to the Design View for forms (Fig. 5.52). Design

    the report in much the same way you would create a form. For example,

    double-click the title bar of the Field Box to add all of the fields to the

    report at once. Then, use the handles on the elements to resize them, move

    them to different locations, and modify the look of the report by using

    options on the formatting toolbar. Click the Print View button at the top,

    left corner of the screen to preview the report.

  • 7/30/2019 Unit 5 Ms Access

    26/28

    105

    Introduction to MS Access

    Fig. 5.52: A Blank Grid, Field Box and Form Element Toolbar for Adding Fields to a

    Report

    Printing Reports

    Select File|Page Setup to modify the page margins, size, orientation, and

    column setup. After all changes have been made, print the report by selecting

    File|Print from the menu bar or click the Print button on the toolbar.

    Self Check Exercise

    2) Give a brief description of a report. Which may be generated using

    ACCESS.

    Note: i) Write your answer in the space given below.ii) Check your answer with the answers given at the end of this Unit.

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    ................................................................................................................................................

    5.9 MACROS AND MODULES

    Macros are a set of actions that one can create to help automating common

    tasks. For example, one can run a macro that prints a report when a user clicks

    a command button. By using groups of macros, one can perform several tasks

    at once. It is a set of one or more actions that each performs a particular

    operation, such as opening a form or printing a report.

    A module is basically a collection of declarations, statements, and procedures

    stored together as one named unit to organise Microsoft Visual Basic code.

    Microsoft Access has two types of modules: class modules and standardmodules.

  • 7/30/2019 Unit 5 Ms Access

    27/28

    106

    Database Concepts Form and report modules are class modules that are associated with a particular

    form or report. Form and report modules often contain event procedures that

    run in response to an event on the form or report. Event procedures can be

    used to control the behaviour of the forms and reports, and their response to

    user actions, such as clicking a command button.

    When first event procedure is created for a form or report, Microsoft Accessautomatically creates an associated form or report module. Standard modules

    contain general procedures that arent associated with any other object, and

    are frequently used procedures that can be run from anywhere within the

    database.

    5.10 SUMMARY

    In this Unit you have learnt some basic concepts of MS Access. MS Access is

    a Relational Database Management System (RDBMS). It is a powerful program

    to create and manage databases. It can be used for various purposes - for personal

    information management in a small business to organise and manage all

    available data in an enterprise to communicate with servers. Using Access one

    can manage information from a single database file. Within the file one can

    use table, queries, forms and reports. It also has facility for customisation using

    macros and modules.

    5.11 ANSWERS TO SELF CHECK EXERCISES

    1) Queries select records from one or more tables in a database so they can

    be viewed, analysed, and sorted on a common datasheet. Queries facilitate

    fast retrieval and display of data from tables. This is very useful whentables are very large.

    2) A report is an organised document that can be used to print from data.

    Reports add formatting to the output including fonts, colors, backgrounds

    and other features. Reports are usually printed out on paper rather than

    just viewed on the screen. A report can include data from various tables,

    queries, forms or data imported from other packages. There are many

    ways to create reports to show summarisation, sorting and layout of the

    data in an organised form. Reports organise and group the information in

    a table or query and provide a way to print the data in a database.

    5.12 KEYWORDS

    Database : A collection of logically related data that

    supports shared access by many users and is

    protected and managed to retain its value.

    Datasheet View : Allows you to update, edit, and delete

    information from a table.

    Design View : Provides the tools for creating fields in a table.

    Event Procedures : A procedure that executes whenever a

    particular event occurs.

  • 7/30/2019 Unit 5 Ms Access

    28/28

    Introduction to MS AccessField : A column on a datasheet which defines a data

    type for a set of values in a table. For a mailing

    list table might include fields for first name,

    last name, address, city, state, zip code, and

    telephone number.

    Object : Acompetition in the database such as a table,query, form, or macro.

    Record : Arecord in a row on a datasheet is a set of

    values defined by fields. In a mailing list table,

    each record would contain the data for one

    person as specified by the intersecting fields.

    Spread Sheet : An application program which manipulates

    numerical and string data in rows and columns

    of cells.

    Table : A grouping of related data organised in fields(columns) and records (rows) on a datasheet.

    By using a common field in two tables, the

    data can be combined. Many tables can be

    stored in a single database.

    Wizard : A wizard is a feature of Microsoft applications

    that lets you work through a series of dialog

    boxes to help you complete a task.

    5.13 REFERENCES AND FURTHER READING

    Access 2000 Tutorial. http://www.fgcu.edu/support/office2000/access/

    Ericson, Gary (2001). Microsoft Office 2000 Resource Kit.- New Delhi :

    Prentice Hall of India.

    http://www.cwnresearch.com/resources/databases/access/tutorials/access2000/

    Access2000Tutorial.html

    http://www.jmu.edu/computing/ittraining/tutorials/microsoft/access/

    index.shtml

    http://www.teachers.ash.org.au/jfuller/access/access2000.htm

    IGNOU, PGDLAN, MLII-001.

    Microsoft Access Tutorial

    http://cisnet.baruch.cuny.edu/holowczak/classes/2200/access/accessall.html