Microsoft Access

Transcription

Microsoft Access
Microsoft Access
Introduction
Starting Access
Access is an interactive, relational database management
system. A database is an organised collection of data stored in
categories that are accessible in a logical or practical manner.
Relational databases enable data to be stored in multiple tables
linked together via data indexes. This makes working with the
data faster and easier. Once entered into the database, the
data may be manipulated or viewed in various ways such as by
sorting or by specially set-up queries and reports.
To start Access, click the Public button on the taskbar, and
choose Access from the MS Office option:
After the initial start-up screen, the Access start-up window
should appear like this:
This is a standard application window with a title bar at the
top containing the minimise and maximise buttons in the
right corner.
Microsoft Access
5-1
Below the title bar, is the menu bar with several of the usual
Windows menus including File, View, Edit and Help.
The Menus
As you perform different tasks in your session the menu and
toolbars will change to display menus and options applicable
to each situation. The initial menu options are as follows.
The File menu allows you to create, open or close databases,
create or rename objects associated with databases, to import
or export data and to print items.
The Edit menu is a standard Windows menu from which you
can copy, paste and delete information and define
relationships between data.
The View menu can be used to specify the object you wish to
see and the style in which it is to be displayed. You can also
choose the style of the toolbars and set certain options.
The Insert menu provides an easy way to create any of the
database objects you may need to use such as tables and forms.
The Tools menu contains utilities for autocorrecting text and
setting database security and encryption. You can also set up
macros containing combinations of commonly used
procedures from here.
The Window menu allows you to arrange the way in which the
various open windows are positioned on the screen.
The Help menu offers three ways of obtaining on-line help.
You can call up the Office Assistant utility, see the contents of
the Access Help system or use the What's This? feature to
point to an object and see a description of it.
Floating Menus
In addition to the normal menus, clicking the right mouse
button whilst the cursor is over an object produces a floating
menu with several of the more commonly used menu options.
You may find this method faster to use.
Toolbar
Below the menu bar is the toolbar. Only three buttons on the
toolbar can be used at this stage. One to create a database, one
to open an existing database and one on the far right which
can be used to obtain help. Many of the menu commands are
duplicated in the toolbar.
In addition to the help system, pointing to any button in the
toolbar will produce a pop-up label to describe the function of
the button. There is also a status bar at the bottom left of the
screen that will display information relevant to the current
activity.
Creating A Database
5-2
To create a database, choose New Database from the File
menu or click on the new database button in the toolbar and
the following window appears:
Microsoft Access
As the Blank Database icon is already highlighted, just click
on OK to produce the next dialogue box:
Type the name of the new database in the File Name box or
accept the default already supplied. The name will have the
extension .mdb added automatically.
Make sure the correct drive (G: or A:) and folder are selected
in the Save in box by selecting from the drop down list visible
when you click on the downward arrow to the right of the box,
then click on the Create button.
The menus and tool bar of the Access window change and a
Database Window appears:
The Database Window contains three main buttons, New,
Open and Design, along with a series of ‘Object’ tabs along the
top.
Microsoft Access
5-3
Objects
Every database can contain several types of object. The data
itself is contained in an object called a table. The data can be
used in a wide variety of formats, for example, mailing lists,
forms, reports and graphs. Each of these is a type of object.
You create objects by clicking on the appropriate tab in the
Database window, then clicking on the New button.
Once objects such as tables have been created, they will be
listed under the object tab whenever it is selected. To open an
existing object, click on its name so that it becomes
highlighted then click on Open.
All objects have properties that can be set to determine how the
object appears or operates.
Tables
A table is the first type of object to create in a database. It is a
way of defining how the data is to be stored. As with all
databases, a table consists of ‘records’ (rows) and ‘fields’
(columns).
Each record represents one individual item in the database,
such as a person in an address book, and each field represents
a component of the record such as a surname or part of an
address.
Access is a relational database management system. This
means that instead of having the data stored in one large file
or table, it can be divided into several smaller tables. This
reduces the amount of duplication of data and makes it easier
to manage. The tables can be related to each other by a
common field such as a case identification number. You can
work with several tables at the same time.
Creating a Table
To create a table, make sure that the Tables object tab is
selected then click on the New button. This presents you with a
dialogue box with five choices:
If you select TableWizard, Access will help you to create a
standard table by using pre-defined fields. Selecting Design
View, on the other hand allows you to design your own table.
5-4
Microsoft Access
Select Design View and click OK to bring up the Table design
window:
In the lower right corner of this window is an area containing
a brief explanation of the section containing the cursor.
Field Names and
Data Types
Each field of the table has three components:
the Field Name, which identifies the data stored in the
field,
the Data Type, which tells Access what kind of data will be
stored in the field, such as text, numbers or dates, and
the Description, which helps the user remember the
purpose of the field.
It is very important to choose the right data type for a field at
this stage. Access will automatically insert a data type when
you name a field but if you need to change it, click on the data
type box, then click on the downward arrow that appears to the
right of the box. You can then choose a new data type from the
drop-down list.
As you type in the name of each field, a Properties section
appears in the lower left corner of the window where you can
optionally define several properties for each field. Here you
can specify the format of the data to be entered and specify
criteria for validating the data as it is entered.
When you have defined the name, data type and properties of
each field, save the table by choosing Save from the File menu.
At this point you will be informed that a Primary key has not
been set and you will be asked if you wish Access to create one.
Primary Keys
A Primary key field is a field that is used uniquely to identify
each record. The field can be used by Access to manipulate
data more efficiently. You do not have to specify a key. If you
wish to use one, you can choose an existing field or, if you
answer yes to the prompt for Access to create a Primary key,
Access will create an extra field containing an ID number for
each case.
Entering Data
Once you have defined the structure of a table, you can start to
enter data into it. You created the table in Design view. To
enter data, switch to Datasheet view by selecting Datasheet
from the View menu. This produces a spreadsheet style
window with the name of each field at the top of a column:
Microsoft Access
5-5
The highlighted box or cell of the datasheet denotes the
insertion point for data. If you requested Access to create a
Primary key, the first cell is a counter called ID, which is
automatically filled in by Access. Press TAB to move to the
next cell containing your first field.
To add a record, just type in the appropriate data for the cell
then press the TAB key to move to the next field. At the end of
each record, pressing TAB will move down to the next record.
Saving Data
You do not have to do anything special to save the data. When
you leave a record to go to the next one or close the table,
Access automatically saves any changes. To close the table
choose Close from the File menu.
Finding Data
The simplest way to find a record in a table is:
From the database window, open the table in Datasheet
view.
Select the field to search by clicking on its name box.
Choose Find from the Edit menu.
Enter the value you want to search for in the Find What?
box and click on Find First.
You can also specify whether the search should match for
case, in which direction to search and whether to search other
fields.
When you initiate a search, the cursor moves to the first
occurrence of the search string in the table and the string is
highlighted. To search for another occurrence of the same
value, use the Find Next button.
Filters
Using Find will only display one occurrence of a search value
at a time. To find all records with a field containing a certain
value, use a filter. For example, you could use a filter to select
all people from a particular town in an address book database.
To create a simple filter:
Open the table from the database window
Move to the column on which you want to use a filter and
click on a cell containing the value that you are interested
in.
Choose Filter by selection from the Record menu
The result is a list of only those records, that contain the same
value as the cell you highlighted.
You can also create a Form Filter that allows for more than
one criterion to be used.
To do this:
Open the table.
Choose Filter by Form from the Filter option in the Records
menu.
Click one of the fields then, from the drop down menu,
choose one of the values that the record must contain to
pass the filter.
5-6
Microsoft Access
To perform several filters and sort functions at the same time
use the advanced filter option:
Open the table from the database window.
Choose Advanced Filter/Sort from the Filter option in the
Records menu. This will open a Filter window in which
you can define the records you want to see.
Click on the required field listed in the upper part of the
window and drag it down to the first Field cell in the lower
part of the Filter window. Or double click on it to copy it
automatically.
Specify search criteria by typing the required value in the
first Criteria cell.
To apply the filter, choose Apply Filter/Sort from the Filter
menu. The required records will be displayed in a
datasheet view.
For example, if you wanted to see all the records of people from
an address database living in London and there was a field in
the table called Town, place the Town field in the Field cell
then type ‘London’ in the criteria cell. The Filter window
would like this:
Remember that you can specify any number of fields using
this method.
Sorting
By default, Access displays the table data in the order in which
it was entered. You can sort an entire table by opening it and
using the Sort option from the Records menu. You can choose
an ascending or descending sort.
You can also use the Filter window to produce a sorted listing
of filtered records by clicking on the Sort Cell in the Filter
window and choosing the required sort from the drop down
menu.
Retrieving Data
- Queries.
Queries enable you to gather data from fields in tables, create
and calculate new fields and summarise data. They are
similar to filters except that they can access fields in more
than one table at a time.
To set a query:
Open the database you want to work on
Click on the Queries tab in the Database window
Click on New. Just as when creating a table, you are given
a choice of using a ‘wizard’ tool to create a standard query
or choosing Design View to design the query from scratch.
Select Design View to display the Show Table dialogue box.
Microsoft Access
5-7
Select the table or tables to be used by the query, clicking
Add after selecting each one.
Close the Show Table dialogue box to reveal the Query
window. The Query window is very like the Filter window
described earlier.
Specify which fields and records you want to retrieve from
the table(s) by pointing to the field name in the Table
window and dragging it to a Field cell in the lower part of
the Query window.
Save the Query and name it using Save from the File
menu.
Choose Run from the Query menu to activate the query.
The fields specified in the query are displayed for each record
in the database. The set of records resulting from a query is
called a dynaset.
You can select as many fields as you wish for the query. Each
time you select one, the check boxes in the Show cells are
checked meaning that the data in the fields will be displayed
when the query is executed. You can vary which fields are
displayed by unchecking any of these boxes.
Specifying Criteria
If you want to restrict the records displayed by a query to those
in which a specified field contains a certain value, use the
Criteria cells of the Query window just as in the Filter window
described earlier.
You can add and combine criteria in the Query window to
create powerful searches to meet exacting conditions. To
modify a query, choose Design View from the View menu or
click on the Design View button.
Forms
You can control the way in which data is displayed by creating
another type of object called a form. To create a form:
Click on the Forms tab in the Database window.
Choose New and Design View. (Once again, you can use
the FormWizard and choose Autoform to let Access
provide you with a ready-made form if you prefer).
Type in the name of a table or query you wish to view or
select it from the list under the down arrow to the right of
the cursor.
Choose Field List from the View menu to display a list of
fields.
Drag the required fields to a position on the form.
Save and name the form using Save from the File menu.
You can also create a form by selecting a table from the
Database window then clicking the AutoForm button on the
toolbar.
Once the form has been created, you can use it to view,
change, add and delete records in the table. To move from
record to record, use the navigation buttons in the corner of
the Form window or use the Go To command in the Records
menu
Forms are convenient when you want to view all the fields of a
single record on the screen. You can switch between Form
view and the original Datasheet view using the View menu or
the appropriate buttons in the tool bar.
5-8
Microsoft Access
To add records using a form, choose the Forms tab in the
Database window then select the form by name. A blank form
appears awaiting data. Press TAB to move between fields and
continue entering the data. At the end of the form, pressing
the TAB key will save the data just entered and take you to
another blank form.
Reports
A report is another type of object much like a form but with
greater flexibility and control when printing data including
various ways of producing summary information.
Macros
A macro is an object used to automate a list of actions. For
example, you might want a set of forms opened automatically
when a database is opened. Macros can be used in a variety of
places, for example, attached to a form, a report or a menu
command.
Modules
Access contains its own programming language, Access
Basic, which can be used to automate more complex processes
than macros can handle. A module is an object containing
Basic procedures.
Linking and
Importing Data
There are two ways of using data that is already stored in
computer form. Firstly, data from different file types such as
spreadsheets and text files can be imported into an Access
table. In this case the data is copied from the original file into
the table.
To import data:
Open the database.
Choose Get External Data, Import from the File menu.
Select the location, the type of data and the specific file in
the Import dialogue box.
Click on the Import button.
Alternatively, you can view and update data stored in another
database or in a file from another package such as Excel or
Paradox without copying or moving the data. To do this, you
link the file to the current database. The original file format is
unchanged.
To link a file:
Open the database.
Choose Get External Link from the File menu.
Select the location, the type of data and the specific file in
the Link dialogue box.
Click on the Link button.
Respond to any further dialogue boxes that appear for
example, to select particular data sets from the selected files.
Note that in the case of linked data, you may not be able save
any changes you make, depending on what access rights you
have to the original file.
Closing and Exiting
When you have finished working with a database, choose
Close Database from the File menu. You may then open
another database or if you have finished your Access session,
choose Exit from the File menu.
Microsoft Access
5-9
Subsequent
Access Sessions
When you start an Access session after having worked with a
database previously, the initial startup process is slightly
different. On start-up, you will see the following dialogue box
giving you the option to start a new database, use the database
wizard or open previously saved databases:
Check the appropriate option and click OK.
5-10
Microsoft Access