Ms Acess
Ms Acess
INTRODUCTION TO DATABASES
In its simplest form, a database is a collection of information that is organized into a list. Whenever you
make a list of information, such as names, addresses, products, or invoices, you are, in fact, creating
database.
A database program lets you:
Store Information
Find Information
Analyze and Print information
Manage Information
Share Information
Databases usually consist of several parts. A Microsoft Access database may contain up to six different
database object types. The table on this page identifies the database objects that you can use when creating
Microsoft Access database. Some objects you will use all the time (such as Tables), others you will hardly
use (such as Modules).
Object Description
Table Tables store a database’s data in rows (records) and columns (fields .A database must
always contain at least one table where it can store information-all the other database
objects are optional.
Forms Forms are custom screens that provide an easy way to enter and view data in a table
or query.
Pages A special type of Web page designed for viewing and working with Microsoft Access
data from an Internet or Internet.
Macros Macros help you perform routine tasks by automating them into a single command.
For example, you could create a macro that automatically opens and prints a report.
Modules Like macros, Modules automate tasks, but by using a built-in programming language
called Visual Basic or VB. Modules are much more powerful and complex than
macros.
1
UNDERSTANDING THE ACCESS PROGRAM SCREEN
Status bar
Figure 1
2
Menus found in Microsoft Access
Menu Description
File File-related commands to open, close, print, and create new files.
Edit Commands to copy, cut, paste, find, and replace text.
View Commands to change how the screen is displayed.
Insert Lists items that you can insert into a database, such as graphics and charts.
Tools Lists tools such the spell checker and macros. You can also change the default for
Microsoft Access options here.
Records Commands to add, delete, sort, and filter information.
Window Commands to display and arrange multiple windows (if you have more than one
file to open.)
Help For assistance or help
Keystroke Description
<Ctrl> + <O> Open a database
<Ctrl> + <W> Close a database
<Ctrl> + <P> Print current view
<Ctrl> + <Z> Undo
<F7> Check spelling
<Ctrl> + <+> New Record
<Ctrl> + <-> Delete record
<Ctrl> + <C> Copies he selected text or object to the Windows clipboard
<Ctrl> + <X> Cuts the selected text or object from its current location to the Windows clipboard
<Ctrl> + <V> Pastes any copied or cut text or object in the Windows clipboard to the current
location
<Ctrl> + <F> Find
<Ctrl> + <H> Find and replace
<Page Down> Next Screen
<Page Up> Previous Screen
3
PLANNING A DATABASE
Planning is the first step in creating a database. You need to decide what you want the tables
to contain and how you want them to be accessed. The main question to ask yourself is,
“What data must be put into the database, to be able to obtain the information I want?”
4
CREATING A DATABASE
1. Start Microsoft Access by clicking the Windows Start button and selecting ProgramsMicrosoft
Access from the Start menu.
The Microsoft Access Program appears with the Microsoft Access dialog box displayed. The
Microsoft Access dialog box gives you quick access to any database you have worked on recently
and allows you to create a new database.
2. Click the Database Wizard option, click OK, and click the Databases tab if necessary.
The New dialog box appears with the Database tab selected. Here you need to select the type of
database you want to create.
3. Type the name of database you want to create and click Create.
The first screen of the Database Wizard appears and describes the database it will create for you.
4. Click Next to continue.
The next screen of the Database Wizard appears. This dialog box displays the standard tables and
fields that the Database Wizard is building for you. Click a table on the left side of the dialog box to
view its fields on the right side. If you want, you can add or remove the standard fields from the
database by checking or unchecking them.
5. Click Next to accept the Database Wizard’s standard tables and fields.
Next, you have to decide what your new database should look like. Access provides you with
several aesthetic styles to choose from. Click a style to see a sample for what it looks like.
6. Select the font style that you like best and click next.
Another screen and more aesthetic decisions to make. Here, you need to select the font you want to
use in your reports. You can preview each of the font styles by clicking them.
7. Select the font style that you like best and click next.
8. Type the title of your database.
This title will appear on the heading of all the reports in your database.
9. Click Finish to create the new database.
10. Explore the tables, forms, and reports in the new database by clicking the various buttons on the
switchboard form.
Move on to the next step when you have seen enough of the new database.
11. Close the new database by selecting FileClose from the menu.
5
b). Creating a blank database
The advantage of creating a blank database is that it gives you the most flexibility and control over your
abase design. The disadvantage of creating a blank database is that you have to create every table, form,
report, and query yourself.
How to create a blank database.
3. Navigate to the drive and folder where you want to save the new database, then type the name in
the File Name box and click Create.
Access creates a new database and saves it using the name you’ve typed. The Database window appears
when it’s finished. If you click the various database object tabs you will notice that there aren’t any
database objects in this database. You will have to create the entire database yourself.
6
CREATING DATABASE OBJECTS
You use the Database window to create, open, modify, and manage all the different types of objects in a
database. The Database window contains tabs for each type of database object
1. TABLES
Tables are where a database stores all its information. All the other database objects-queries, forms, reports,
and macros-are merely tools to analyze and manipulate the information stored in a table. Any of these
other database objects are optional-but without tables a database wouldn’t be a database. Each table in a
database stores related information. Most databases have more than one table: each table is used to store a
different type of information. For example, one table might contain a list of customers and their addresses,
while another table might contain any orders placed by the customers, while yet another table might contain
a list of products.
Tables are made up of groups of fields. A field is a specific type of information, such as a person’s last
name, address or phone number. Together, the related fields for each individual person, place, or thing
make up a single record. If your company has ten employees, your employee table would have ten records-
one for each employee.
If you’re new to Access, the easiest way to add a table to an existing database is with the Table Wizard. The
Table Wizard asks you a series of questions about what fields you want to appear in your table and does the
dirty work of creating a new table for you. The Table Wizard can create a variety of different tables to store
mailing lists, inventory, catalogs and more.
7
4. You start the Table Wizard by selecting the sample table you want to use from the Sample table list
The Table Wizard displays the ready-made fields that you can incorporate into your table in the
Sample Fields list. To add a field to your table double-click the field or select the field and click the
button. Click the button to add all the sample fields to your table.
5. Click Next. The Table Wizard asks you to give your table a name and if you want to have, Access set
a primary key for you.
NOTE: If other tables exist in your database, another screen will appear, asking you how this table
relates to the other tables in your database.
6. Click Finish to create the new table.
The Table Wizard builds the table using the fields you selected and then opens the new table-ready for
your data input.
7. Close the table
8
MODIFYING A TABLE AND UNDERSTANDING DATA TYPES
Once you have created a table, you can modify it later in Design View. Design View allows you to change
the structure of a table by adding, deleting, and modifying its fields.
Because there are so many different types of data, Access offers several different types of fields. A field’s
data type determines the type of information that can be stored in a field. Data Types lists the various data
types available in Access. For example, you cannot enter text into a number data type field.
9
UNDERSTANDING FIELD PROPERTIES
A property is an attribute that defines an object’s appearance, behavior, or characteristics. For example, a
car’s properties would include its color, make and model, and shape. A property for a numeric field might
be the number of decimal places displayed or the maximum number of characters a field can hold.
Field Properties
Field Size Text fields: The maximum number of characters (up to 255) that can be entered in
the field. The default setting is 50.
A primary key is a special kind of indexed field that uniquely identifies each record in a table. When you
think about primary key fields think unique-each primary key value must be the only one of its kind in a
table. E.g. a customer ID or invoice number would be two good examples of fields that could be used as a
table used as a table’s primary key.
Here are some things you need to know about primary keys:
A table can only have one primary key.
The values in the primary key fields must be unique. AutoNumber fields automatically add a new,
unique number to each record in a table.
Every table you create should have a primary key because it helps keep your data organized and easy
to work with.
Yes/No, OLE, and hyperlink fields can’t be used as the primary key.
The primary key is normally a single field, but two or more fields can act together as the primary
key, so long as their combined values are unique.
Primary keys are especially important in creating relationships between tables.
10
To add a primary key to a table then make sure it is in design view. Select the fields you want to use as a
primary key then on edit menu click primary key or Click the Primary Key button on the toolbar. A picture
of a key appears at the beginning of the row. Now save the changes made.
You can insert, delete, and reorder fields in your tables in Design view. Remember that in Design view for
tables, each row corresponds to a field. You add a field by inserting a new row and delete a field by
deleting its corresponding row by selecting on a row then insert using insert menu or delete using edit menu.
You can enter a Default Value to specify a value that is automatically entered in a field when a new record
is created. For example, if most of your clients are from Texas, you could set the default value for the State
field to “TX”. When a user adds a record to the table, they can either accept the TX default value for the
State field or enter their own value.
11
VALIDATING DATA
Without a doubt, data validation is thee most powerful tool you can use to prevent data entry errors. With
data validation, Access actually tests data to make sure that it conforms to what you want to appear in the
table. If the incoming data doesn’t meet your requirements, Access kicks it out and displays an error
message.
Data validation works best in number, currency, and date/time fields. You can create a validation rule for
text entries, but doing so can be complicated-especially if you want to test a lot of text variables.
There are actually two boxes that relate to data validation. They are the:
Validation Rule box: Use to specify the requirements for data entered into the field.
Validation Text box: When data is entered that violates the validation rule you can use the
Validation Text box to specify the message to be modify and use in your table.
Creating data validation rules can be a little tricky-you create a data validation using the same hard-to-
remember operators that you use in filters and queries. Table 4-7: Data Validation Examples contains some
data validation that you can modify and use in your tables.
Consider the following table. It contains samples of the most common types of validation rules. Feel free to
copy, modify, or mix and match these examples to create your own validation rules.
12
CREATING AN INPUT MASK
An Input Mask limits the amount and type of information that can be entered in a field.
There are two ways to create an input mask:
Click the Build button and have the Input Mask Wizard create the input mask for you (the fast and
easy way). The only problem with the Input Mask Wizard is that it can only help you create input
masks for phone numbers, Social Security numbers, zip codes, and date and time fields.
Create the input mask yourself by typing a series of characters in the Input Mask box (the hard way).
If you want to use this brutal method refer to Table 4-8: Input Mask Characters to see what you have
to enter to create an input mask.
Creating an input mask by hand is difficult but it can be done. You need to create the input mask by
entering the characters shown in the following table in the Input Mask box.
Character Description
0 Numbers 0 to 9 required; plus and minus signs not allowed
9 Number or space optional plus and minus signs not allowed
# Number or space optional plus and minus signs not allowed
.,:;-/ Decimal point, thousands, date, and time separators
A Letter or number Required
A Letter or number optional
L Letters A to Z required
? Letter or number optional
& Character or space required
C Character or space optional
< Converts the following characters to lowercase
> Converts the following characters to uppercase
! Displays characters from right to left, rather than Left to right
\ Displays the following input mask character. For Example, \* would display *
Password Displays an asterisk (*) for Each character you type
13
CREATING A LOOKUP FIELD/ VALUE LIST
Lookup fields are defiantly one of the coolest and most powerful features in Access. A lookup field lets you
pick a field’s entry from a list of values. Similar to its cousin the lookup list, a value list displays list of
values in a drop-down list. Unlike a lookup list, which displays data in a table or query, a value list displays
a list of options that you manually enter. A value list is useful if you enter the same data in a field
repeatedly. There are two ways that a lookup field can get its list of values:
From a list of values or options that you enter yourself. For example you could add the values
FedEx, UPS, and Airborne to a field.
From a list of values in a table or query. For example, instead of entering a CustomerID from a list
of names.
RELATIONSHIP
An association established between common fields (columns) in two tables. A relationship can be one-to-
one, one-to-many, or many-to-many.
In a relational database, relationships enable you to prevent redundant data. For example, if you are
designing a database that will track information about books you might have a table called titles that stores
information about each book, such as the book’s title, date of publication, and publisher. There is also
information you might want to store about the publisher, such as the publisher's phone number, address, and
zip code. If you were to store all of this information in the titles table, the publisher’s phone number would
be duplicated for each title that the publisher prints.
A better solution is to store the publisher information only once in a separate table, publishers. You would
then put a pointer in the titles table that references an entry in the publisher table.
To make sure your data is not out of sync; you can enforce referential integrity between the titles and
publishers tables. Referential integrity relationships help to ensure information in one table matches
information in another. For example, each title in the titles table must be associated with a specific publisher
in the publisher’s table. A title cannot be added to the database for a publisher that does not exist in the
database.
14
How Do Relationships Work?
A relationship between tables works by matching data in key fields. These key fields usually have the
same name in the two tables. For example, both the Customer table and the Orders table have a
Customer ID field.
Records in the Orders table that have the same Customer ID as a record in the Customer table would be
orders placed by that customer.
Benefits of Relationships
You will see many benefits by linking the tables in your database before you begin creating forms, reports
and queries.
Data Integrity:-Relationships will not allow creating records in a secondary table unless
there is a matching record in the master table. For example, an order could not be placed in the order
table for a non-existent customer.
Optimal Performance: - When running reports and queries, having relationships
established assures optimal performance.
Ease of Use in Designing Systems:- If the relationships have been established then it
will be much faster and easier to design the forms, reports and queries needed in the database.
One-to-Many Relationships
A one-to-many relationship is the most common type of relationship. In this type of relationship, a row in
table A can have many matching rows in table B, but a row in table B can have only one matching row in
table A. For example, the publishers and titles tables have a one-to-many relationship: each publisher produces
many titles, but each title comes from only one publisher.
A one-to-many relationship is created if only one of the related columns is a primary key or has a unique
constraint.
Many-to-Many Relationships
In a many-to-many relationship, a row in table A can have many matching rows in table B, and vice versa.
Example is a relationship between distributors and products. i.e. one distributor distributes many products
and one product can be distributed by many distributors.
One-to-One Relationships
In a one-to-one relationship, a record in a table specifically relates to one record in another table i.e. A can
have no more than one matching row in table B, and vice versa. A one-to-one relationship is created if both
of the related columns are primary keys or have unique constraints.
15
This type of relationship is not common because most information related in this way would be all in one
table. You might use a one-to-one relationship to:
You can't enter a value in the foreign key column of the related table if that value doesn't exist in the
primary key of the related table. However, you can enter a null in the foreign key column. For
example, you can't indicate that a job is assigned to an employee who isn’t included in the employee
table, but you can indicate that an employee has no assigned job by entering a null in the job_id
column of the employee table.
You can't delete a row from a primary key table if rows matching it exist in a related table. For
example, you can't delete a row from the jobs table if there are employees assigned to the job
represented by that row in the employee table.
You can't change a primary key value in the primary key table if that row has related rows. For
example, you can't delete an employee from the employee table if that employee is assigned to a job in
the jobs table.
You can set referential integrity when all of the following conditions are met:
The matching column from the primary table is a primary key.
The related columns have the same data type and size.
Both tables belong to the same database.
16
the pub_id column in the publishers’ table to the pub_id column in the pub_ info table, then the publishers’ table is
on the primary key side of the relationship.
The foreign key side of a relationship is denoted by a key symbol for a one-to-one relationship or an infinity
symbol for a one-to-many relationship.
Tip If you want to see labels for relationship lines, use the Show Relationship Labels command.
determines what records the filter returns. For more information on selecting values, click .
Repeat step 2 until you have the set of records you want.
2. Click in the column to the right of where you want to insert a new column, and then on the Insert
menu, click Column.
3. Double-click the new column's name and then type a name for the column If you want to customize
a field's definition further — for example, to change its data type, or define a validation rule, use
table Design view.
17
2. CREATING A QUERY
You can create a query using different ways like
Using the design view
Using the wizard.
BETWEEN BETWEEN 1/1/99 AND 12/31/99 Finds records between 1/1/99 AND
12/31/99
18
3. CREATING A FORM
You can create a form by
Using the Auto form
Using a wizard
Creating a form in design view.
Note You don't need to do this step if you click the Form Wizard option — you can specify the
record source for the form in the wizard.
5. Click OK.
6. If you clicked Form Wizard, Chart Wizard, or PivotTable Wizard in step 3, follow the directions
in the wizard dialog boxes.
19
to open other forms or reports, or if you want to create a custom dialog box), don't select anything
from this list.
Note If you want to create a form that uses data from more than one table, base your form on a
query.
5. Click OK.
6. on the field list listbox drag the fields you want and drop them on the form.
7. arrange you fields in the best way you like then save your form and run it to display the record
you’ve entered or to enable you to enter the records on the table.
Add or remove a form header and footer or a page header and footer
Notes
Form headers and footers appear at the top and bottom of a form in Form view and at the beginning
and end of a printed form. Page headers and footers appear at the top and bottom of each printed
page — they don't appear in Form view.
If you remove a header and footer, Microsoft Access deletes the controls in the header and footer.
You can only add a header and footer as a pair. If you don't want both a header and a footer, you can
size the one you don't want so that it has no height, or you can set its Visible property to No. You
can also set the Display When property of a form header and footer to specify when you want the
header and footer to be displayed ? always, in print only, or on the screen only.
20
Note It doesn't matter which table or query you choose first.
7. Double-click the fields you want to include from this table or query.
8. When you click Next, if you set up the relationships correctly before starting the wizard, the wizard
asks which table or query you want to view by. Using the same example, to create the Categories
form, click By Categories.
9. In the same wizard dialog box, select the Form with Sub form(s) option.
10. Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft
Access creates two forms, one for the main form and subform control, and one for the sub form.
21
4. Create a report
You can create a report by
Create a report by using Auto Report. With Auto Report, you select one record source and either
columnar or tabular layout; Auto Report uses all the fields from the record source and applies the
last auto format you used to the report.
Create a report with a wizard. The wizard asks you detailed questions about the record sources,
fields, layout, and format you want and creates a report based on your answers.
Create a report in design view
Note Microsoft Access uses this table or query as the default record source for the report. However,
you can change the record source in the wizard and select fields from other tables and queries.
5. Click OK.
6. If you clicked Report Wizard, Chart Wizard, or Label Wizard in step 3, follow the directions in
the wizard dialog boxes. If you click AutoReport: Tabular or AutoReport: Columnar, Microsoft
Access automatically creates your report.
If the resulting report doesn't look the way you want, you can change it in Design view.
22
Tip If you want to create a report that uses data from more than one table, base your report on a
query.
5. Click OK.
6. On the field list box drag the fields that you want and drop them on the report design view.
Add or remove a report header and footer or a page header and footer
Notes
You can add a header and footer only as a pair. If you don't want both a header and footer, set the
visible property to No for the section you don't want. Or remove all controls from the section, and
then size the section to zero height or set its Height property to 0.
If you remove a header and footer, Microsoft Access also removes the controls in the header and
footer.
2. Click the control that contains the text you want to change.
3. On the Form/Report Formatting toolbar, click Bold to make the text bold, Italic to make the text
italic, or Underline to make the text underlined.
23