You are on page 1of 32

DATABASES

Structure Page No.


1.0 Introduction 1
1.1 Objectives 1
1.2 Introduction to MS-Access 2
1.3 Working with MS-Access 3
1.4 Creating Database with MS-Access 3
1.5 Interconnectivity 4
1.6 Summary 5

1.0 INTRODUCTION
Databases are probably one of the most common use of computers to store and
manage information. A database is a collection of data that is organized so that its
contents can easily be accessed, managed, and updated. Databases are not specific to
computers. Example of database we use in our daily life is phone book .It can store
all sorts of information like Name ,Phone number ,address and allow quick searching.
Databases allow adding, deleting, updating and retrieving of data quite easily, as well
as sorting and searching. Databases were compact, fast, easy to use, current, accurate
and were secure. Database is managed using a software called Database Management
System(DBMS).The software allows the users to organize data into databases and
helps in retrieving the data very quickly and easily. The examples of DBMS software
are Microsoft Access, Oracle, Sybase etc. This unit attempts to provide you the basic
skills of MS-Access database with a working knowledge of how to maintain and
effectively utilize a simple database including database creation, integrity
enforcement, query formulation, forms and report creation, etc.

1.1 OBJECTIVES

After going through this unit, you should be able to:

• Create a simple Microsoft access database.


• Creating tables and Enter /edit records.
• Enforce integrity constraints on databases.
• Design Select queries to display data.
• Develop forms/reports using sample interface.
• Find, sort data.
• Connect MS-Access to different front-ends.

1
1.2 INTRODUCTION TO MS-ACCESS

Let's start with basic terminologies used in this unit:

Data: is the information needed to be stored electronically in such a way to easily


use it later.

Database: is a collection of related data in the subject of interest.

Database Management System: is the software used to manage storing the data and
inquire it. Examples of such systems are Microsoft Access, Oracle, DB2, MySQL,
etc.

Microsoft Access is a Relational Database Management System (RDBMS) from


Microsoft . The relational data model specifies data stored in relations that have some
relationships among them . It used to create small and midsize databases for
the Microsoft Windows family of operating systems. It can also be used as a
database server for a web-based application.In relational databases such as Sybase,
Oracle, IBM DB2, MS SQL Server and MS Access, data is stored in tables made up
of rows and columns. MS-Access provides you with the software tools you need to
create and organize the data in a flexible manner . There are four major database
components in Access namely Tables, Queries, Forms and Report.

MS Access database consists of several database components.

Tables : Tables are the main units of relational database where the actual data is
entered. Tables consist of records (rows) and fields (columns).

Queries : Queries are basically a mechanism that allow you to extract data based on
the criteria you define about the data in a database. A query retrieves required fields,
records, and summaries you want to see from a database.

Forms : Forms provide a quick and easy way to modify and insert records into your
databases.Forms are nice front ends for accessing the data that is stored in database
tables or that is generated by queries.

Reports : A report shows selected records in a user-designed format.

Pages : A data Access page is a special type of Web page designed for viewing and
working with data from the Internet or an intranet. This data is stored in a Microsoft
Access database or a Microsoft SQL Server database.

Macros : A macro is a set of one or more actions that each performs a particular
operation, such as opening a form or printing a report. Macros can help you automate
common tasks. For example, you can run a macro that prints a report when a user
clicks a command button.

Modules :In MS Access all code is stored in "Modules".A module is a collection of


Visual Basic code for Applications.

2
1.3 WORKING WITH MS-ACCESS

Like any other computer application, in order to use Microsoft Access, you must first
install it. After installing Microsoft Access, then you can open it. To start Access,
click on the Start button, then the All Programs menu, then move to the MS Office
menu and finally click on the Microsoft Access 2003 menu item. Your screen should
look like this.

The user can create a new database , or open up an existing database. In general, the
first time one begins a project, Create a new file option should be used to create a
blank database d. After that point, use the Open option to re-open the database
created previously. By clicking Create a new file option the following screen will
appear

3
By selecting Blank Database and clicking on the OK button, the following screen
will appear in order to give the new database filename.

Fill in File Name as Employee.mdb and click on the Create button to create the
database .
The window for the Employee database should open as shown in the figure

4
Microsoft Access (MS Access) enables one to manage all important information from
a single database file. Within the file, one can use:
Tables to store your data.
Queries to find and retrieve specific data of interest.
Forms to view, add, and update data in tables.
Reports to analyze or print data in a specific layout.

In the Objects list, click Tables the following screen will appear

Click Queries the following screen will appear

5
Click Forms the following screen will appear

Click Reports the following screen will appear

6
Click Pages the following screen will appear

1.4 CREATING DATABASE WITH MS-ACCESS

1.4.1 WORKING WITH TABLES

Creating a Table Using the Design View


To create a table in Access using the Design View, double click on the "Create Table
in Design View" item. The Table Design View will appear. Fill in the Field Name,
Data Type and Description for each column/field in the table as shown in the figure

7
Define a primary key field before saving your table
Click Save on the toolbar, and then type a name for the table. Avoid including spaces
in your table name or using long names. Click View | Datasheet View to begin
entering data in the table.
Click View | Datasheet View to begin entering data in the table the following screen
will appear

Create a table by using 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 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.
• 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.
• Click Create to start defining your new database

8
Select the sample table that we want and then select the items we need into the new
table.

Press next.

9
Enter the name of the table.

10
Enter the data into the table that was created through wizard.

11
Creating a table by entering the Data:

12
1.4.2 WORKING WITH QUERIES
we use queries to view, change, and analyze data in different ways. You can also use
them as the source of records for forms and reports.

Creating a query in the design view:

13
If we want the details of only EmployeeID and Name then the query editor for this
will be as follows:

14
Create a query using wizard:

15
16
1.4.3 WORKING WITH FORMS

A form is nothing more than a graphical representation of a table. You can add,
update, delete records in your table by using a form.
NOTE: Although a form can be named different from a table, they both still
manipulate the same information and the same exact data. Hence, if you change a
record in a form, it will be changed in the table also. A form is very good to use when
you have numerous fields in a table. This way you can see all the fields in one screen,
whereas if you were in the table view (datasheet) you would have to keep scrolling to
get the field you desire.

Create a form in Design view:

17
Create a Form using the Wizard

It is a very good idea to create a form using the wizard, unless you are an advanced
user and know what you are doing. Microsoft Access does a very good job of creating
a form using the wizard. The following steps are needed to create a basic form:

1. Switch to the Database Window. You can do this by pressing F11 on the
keyboard.
2. Click on the Forms button under Objects on the left side of screen
3. Double click on Create Form Using Wizard
4. On the next screen select the fields you want to view on your form. Most of
the time you would select all of them.
5. Click Next
6. Select the layout you wish
7. Click Next
8. Select the style you desire...HINT: if you plan on printing your form, I
suggest you use a light background to save on printer toner and ink
9. Click Next
10. Give you form a name, and select Open the Form and enter information
11. Select Finish
12. You should see your form. To adjust the design of your form, simply hit the
design button (same as with the tables), and adjust your form accordingly

18
19
20
21
1.4.4 WORKING WITH REPORTS

A report is an effective way to present your data in a printed format. Because you
have control over the size and appearance of everything on a report, you can display
the information the way you want to see it.

Create a Report using the Wizard As with the Form, it is a very good idea to create
a report using the wizard, unless you are an advanced user. Microsoft Access does a
very good job using the wizard to create reports.

1. Switch to the Database Window. You can do this by pressing F11 on the
keyboard.
2. Click on the Reports button under Objects on the left side of screen
3. Double click on Create Report Using Wizard
4. On the next screen select the fields you want to view on your form. Most of
the time you would select all of them.
5. Click Next
6. Select if you would like to group your files. Keep repeating this step for as
many groupings as you would like.
7. Click Next
8. Select the layout and the paper orientation you desire
9. Click Next
10. Select the style you desire...HINT: if you plan on printing your report, I
suggest you use a light background to save on printer toner and ink
11. Click Next
12. Give you report a name, and select Preview the Report
13. Select Finish
14. You should see your report. To adjust the design of your report, simply hit the
design button (same as with the tables), and adjust your report accordingly.

22
23
24
25
26
1.5 INTERCONNECTIVITY

Using Visual Basic as a Front-End to MS-Access


After launching Visual Basic and Opening a Standard Visual Basic Form, the
following screen will appear

1) Create a Data Object (usually it is the second to last object on the toolbox. If
you pass your mouse over, it will show Data).

2) Double click on the Data object to create an instance of the data object on your
Form

27
3) With your property windows open (if it is not open go to view menu and select
property window), select the data object (by clicking once). A window with
the properties of the Data Object should appear.
a. Associate a Database Name (mdb file) to the Data object.
Associate the Northwind database (or any mdb file on your disk).

b. Associate a RecordSource (table) to the Data object. You can


associate the Customers table of the Northwind database.

28
4) You will now create a TextBox Field for each field that you want to access
from your database table. With the property windows open, select the textbox
field.
Create two textboxes by double clicking on the textbox template from the
tools menus. After each instance of a textbox is created on your form, drag the
textbox to the appropriate position on the form.
a. For the Datasource property of the field, select the name of the Data
Object you defined in step 2 (it is Data1 if you haven’t changed the
name of the data object..
b. For the Data Field property of the textbox, select the appropriate field.
Select customer If for the first textbox and contact name for the second
textbox.

5) Run your program and click on the arrows to move to next record an previous
record.

29
30
Session-1 (3 hours)

Question 1:Create a blank database named LIBRARY.


Question 2:Add the following fields to LIBRARY:
• Accession Number
• Title
• Author
• Publisher
• Cost

You can change the names of fields as per need. Also,


assign appropriate data type and size to each field.

Question 3:Add at least 10 records

Question 4:Add two new fields to the above table namely, Year
of publication and ISBN number.

Question 5:Add data to the two new fields for all the 10 records.

Question 6:Create a Form consisting of all the fields of the


LIBRARY. Assign the title BOOK INFORMATION to the form.

Question 7:Create a Report consisting of all the fields of the


LIBRARY. Assign the title REPORT ON BOOKS.
Question 8:Create a Form using Visual Basic that can
accommodate all the fields of LIBRARY.

Question 8:Connect the form created in Visual Basic to


LIBRARY in MS-Access
Question 9:View the records of LIBRARY in the form.

1.6 SUMMARY
In this unit, MS-Access was introduced. Its various components as well as the
process of working with it was explained. The process of creation of a database was
demonstrated. Also, the process of creation of queries, forms and reports was also
discussed. One of the most important features of any DBMS is its ability to connect to
various front-ends. In this unit, the process of connecting Visual Basic to MS-Access
is explained.

1.7 Further Readings

31
• Access 2003 All-in-One Desk Reference for Dummies (Paperback) by John
Kaufeld; 2003
• Microsoft Office Access 2007 Inside Out by John Viescas and
Jeffconrad;Microsoft Press; 2007
• Access 2007 by Rutkosky; BPB Publications
• http://office.microsoft.com/access

32

You might also like