You are on page 1of 28

UNIT 5

Structure 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9

INTRODUCTION TO MS ACCESS

Objectives Introduction MS Access Interface Screen Layouts Getting Started with MS Access Database Objects: Tables Database Objects : Queries Data Objects : Forms Data Objects : Reports Macros and Modules

5.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 database file. Within the file, one can use:
80

Tables to store data.

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. Data access 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 of fields 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

Introduction to MS Access

Object Table

Object Type This object type multiple records entered, edited, s A way of reque query, a selected edit or print the R Through a screen Forms allow you alternative to disp A design for prin as database repo

Query

Form

Report

For a thorough knowledge of how MS Access works it is important to understand the hierarchy of a database in Access.

81

Database Concepts

Database File

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

Table is a collection of data on a specific 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. 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). Value is the element entered for each field for instance a particular authors surname.
Fig. 5.1: Hierarchy of database in MS Access (Source: PGDLAN, Block-1)

Field

Data type

Value

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 Title

Fig. 5.2: MS Access Interface

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

File- This provides the options to open, close, create new, save, print, send, recently opened databases and exit.

Introduction to MS Access

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

83

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.

84

Introduction to MS Access

Fig. 5.11: Design View

Datasheet 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

85

Database Concepts

2)

Click on start button Access (Fig. 5.14).

. Then go to programs and select Microsoft

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 database Expert 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, click Access 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)
86

On the Databases tab, double-click the icon for the kind of database you want to create. Specify a name and location for the database.

3)

4)

Click Create to start defining your new database. 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).

Introduction to MS Access

Create a database without using the Database Wizard

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

87

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 generic names 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 OK button.

88

Fig. 5.18: Creating a New Table

In the Table Design view fill in the Field Name, Data Type, and Description for each field as shown in the figure.

Introduction to MS Access

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 popup 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.
89

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).

90

Fig. 5.23: Naming the Table

After this you may select options for inputting data into the table (Fig. 5.24).

Introduction to MS Access

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.
91

Database Concepts

5.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 a common 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.

New

Design View

Fig. 5.27: Queries page on the Database Window 92

Select Design View and click OK (Fig. 5.27). Select tables and existing queries from the Tables and Queries tabs and click the Add button to add each one to the new query (Fig. 5.28). Click Close when all of the tables and queries have been selected.

Introduction to MS Access

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 Table row Sort row Criteria row shows the name of the fields included in the query. shows the name of the table that the field comes from. allows you to specify the order in which the records are displayed. allows you to specify criteria for including or excluding records from the results set.

Field Row Table Row Sort Row Criteria Row

Fig. 5.29: Query Form

93

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 Wildcard / Operator
? * <100 >=1 <>"INDIA" Between 1 and 10 Is Null Is Not Null Like "R*"

The qu a singl The as charac Value Value Not eq Numb Finds or all r All wo

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.

Table/Queries

> Button >> Button

Fig. 5.30: Access Query Wizard 94

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

menu. 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.

Introduction to MS Access

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 applied to from the list provided and click Next button (Fig. 5.33).
95

Database Concepts

Table or Query

Fig. 5.33: Selecting Table or Query for Duplicate Query

Select the fields that may contain duplicate values by highlighting the names in the Available 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 96

Name the new query and click Finish(Fig. 5.36).

Introduction to MS Access

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. Write your answer in the space given below. Check your answer with the answers given at the end of this Unit. ii) Note: i)

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

5.7
Forms

DATA OBJECTS: 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 records are displayed below like a spreadsheet. Most suitable for displaying multiple records is of data at a time.

97

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 the Available Fields window 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 < or left double arrow << buttons. After the proper fields have been selected, click the Next button to move on to the next screen.

Fig. 5.37: Select Fields Required on the Form

On the second screen as screen in Fig. 5.38, select the layout of the form. i) ii) Columnar - A single record is displayed at one time with labels and form fields listed side-by-side in columns Justified - A single record is displayed with labels and form fields listed across the screen

iii) Tabular - Multiple records are listed on the page at a time with fields in columns and records in rows iv) Datasheet - Multiple records are displayed in Datasheet View Click the Next button to move on to the next screen.

98

Introduction to MS Access

Fig. 5.38: Select the Layout of the Form

Select a visual style for the form from the next set of options (Fig. 5.39) and click Next.

Fig. 5.39: Select Visual Style for the Form

On the final screen (Fig. 5.40), name the form in the space provided. Select Open the form to view or enter information to open the form in Form View or Modify the forms design to open it in Design View. Click Finish to create the form.

Fig. 5.40: Naming the Form

99

Database Concepts

Create Form in Design View To create a form from scratch without the wizard, follow these steps: Click the New button on the form database window. Select Design View and choose the table or query, the form is required to be associated with the form, from the drop-down menu. Select View|Toolbox from the menu bar to view the floating toolbar (Fig. 5.41) with additional options.

Fig. 5.41: Floating Toolbar

Add controls to the form by clicking and dragging the field names from the Field List floating window, as shown in Fig. 5.42. Access creates a text box for the value and label for the field name when this action is accomplished. To add controls for all of the fields in the Field List, doubleclick the Field List windows title bar and drag all of the highlighted fields to the form.

Fig. 5.42: Adding Controls to the Form

Adding Records Using a Form Input data into the table by filling out the fields of the form (Fig. 5.43). Press the Tab key to move from field to field and create a new record by clicking Tab after the last field of the last record. A new record can also be created at any time by clicking the New Record button at the bottom of the form window. Records are automatically saved as they are entered so no additional manual saving needs to be executed.

100

Introduction to MS Access

Fig. 5.43: Entering Records Using a Form

Form Appearance - Change the background colour of the form by clicking the Fill/Back Color button on the formatting toolbar (Fig. 5.44) and click one of the colour swatches on the palette. Change the colour of individual form objects by highlighting one and selecting a colour from the Font/ Fore Colour palette on the formatting toolbar. The font and size, font effect, font alignment, border around each object, the border width, and a special effect can also be modified using the formatting toolbar.

Fig. 5.44: Buttons on the Formatting Toolbar

Page Header and Footer - Headers and footers added to a form will only appear when it is printed. Access these sections by selecting View|Page Header/Footer on the menu bar. Page numbers can also be added to these sections by selecting Insert|Page Numbers. A date and time can be added from Insert|Date and Time. Select View|Page Header/Footer again to hide these sections from view in Design View.

5.8

DATA OBJECTS: REPORTS

A report is an organised document that can be used to print form 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. Create Report Using Wizard Create a report using Access wizard by following these steps: Double-click the Create report by using wizard option on the Reports Database Window.

101

Database Concepts

A new screen appears as shown in Fig. 5.45. Select the information source for the report by selecting a table or query from the Tables/Queries dropdown menu. Then, select the fields that should be displayed in the report by transferring them from the Available Fields menu to the Selected Fields window using the single right arrow button > 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.

102

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 to create the report.
103

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.
104

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) ii) Write your answer in the space given below. 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 standard modules.
105

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 Access automatically 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 when tables are very large. 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.

2)

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. : Allows you to update, edit, and delete information from a table. : Provides the tools for creating fields in a table. : A procedure that executes whenever a particular event occurs.

Datasheet View Design View Event Procedures


106

Field

: 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. : A competition in the database such as a table, query, form, or macro. : A record 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. : An application program which manipulates numerical and string data in rows and columns of cells. : 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. : A wizard is a feature of Microsoft applications that lets you work through a series of dialog boxes to help you complete a task.

Introduction to MS Access

Object Record

Spread Sheet

Table

Wizard

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

107

You might also like