acess tutorial best
acess tutorial best
What is Access?
Access is part of the Microsoft Office suite of applications. It is a relational database management system
(RDBMS). This means that not only does Access have tables, but it also has other database objects (forms, queries,
and reports) that help you with managing the data in your tables. It also means that Access stores data in a relational
manner. Access’s main purpose is to record large amounts of information in a relational manner.
Access is a desktop database system. It is meant to be used in a small office environment. Access is not a
database server and cannot respond to hundreds of queries per second like a server database.
Sometimes it is a good idea to compare Access to Excel to get an understanding of the difference between the two
products. Excel is a spreadsheet application that is meant to be used to analyze small amounts of data, whereas
Access is a database application that is meant to be used to store large amounts of data in a relational manner.
Many people start saving their data in a spreadsheet. A spreadsheet, or worksheet, has a user friendly row and
column layout that most people understand. Data stored in an Excel worksheet in a row/column fashion is called a
list. A list in Excel is very similar to a table in Access; the two are interchangeable. In fact, a list in Excel can be
imported into Access as a table, and a table in Access can be exported to a list in Excel. A list in Excel can have
up to 65,000 rows, and a table in Access can have millions of records (rows).
A worksheet in Excel has rows and columns, where a table in Access has records (rows) and fields (columns). An
Excel workbook can only have 256 worksheets; an Access database can have 32,000 tables. The main difference
between Access and Excel is that Excel does not have the capability to relate data in one list with data in another
list. Access will let you relate data in one table to data in another table.
You can use either Excel or Access to store your data. They both can perform many of the same database type
functions:
The key to making a decision to use Excel or Access to save your data depends on the complexity or
amount of data.
Is there more than one entity involved? An entity is a major subject of your data. Entities usually become tables in
your database. If your data consists of names, addresses, and phone numbers of people, what most people would
call an address book, each record (row) is about a person, or in other words, one entity. This type of data is called
flat. Flat data can be easily recorded and managed in a list in Excel, or in one table in Access. So, if your data is flat
and will be in the thousands of records, or less, Excel would be a good choice.
The need for an Access database really comes in when you have more than one entity in your data model and/or you
will have hundreds of thousands of records or less. For example, using the address book example above, if you need
to record the actions of people in the address book. Let us imagine that you will need to record a sale of merchandise
and relate the sale to a person in your address book (we can call them customers if we want, they are still people),
then you would have data consisting of two entities: a customer, and a sale. In this scenario, you would need two
tables: a customer table, and a sale table. In the customer table, each record would have information about the
customer, and in the sale table, each record would have attributes of the sale, such as, a date, time, tax rate, and the
customer number to which the sale is related. The sale table would need to be related to the customer table. Excel
does not do relationships.
We will cover more about relationships in the “Designing a Database” section of this booklet.
When you roll your mouse over an Office Button item with an arrow displays a list of sub‐items.
The Menu Bar and Toolbars have been replaced by the Ribbon, a panel that contains functional groupings of
buttons and drop‐down lists organized by tabs. Each application in the Office Suite has a different set of tabs (with
some tabs in common) that pertain to the functionality of that particular application. Each tab is further divided into
groups (of buttons), such as the Font and Paragraph groups shown above.
There are also “contextual tabs” that appear, depending on what you’re working on. For example, if you have a
table open in the “Normal” view, the “Table Tools” tab with a “Datasheet” tab is shown.
The Quick Access Toolbar is a small toolbar at the top left of the window that you can customize to contain the
buttons for the functions that you use most often. In essence, it is the same as the toolbars from previous versions of
Office with only the buttons you want to see on it.
To customize the Quick Access Toolbar, click on the drop‐down arrow on the far right. You can add or remove
items from the Toolbar, as well as show the Toolbar below the Ribbon, rather than above, and minimize the
Ribbon.
Access 2007 uses an XML‐based file format (ACCDB). Database files saved with Access 2007 will have the
filename extension “.accdb”. If you have databases in earlier formats, you can convert them to the new format.
4. Click “Save”.
Some new features have been added to the Access 2007 file format:
Multi‐valued fields
When you open an Access database, you will see a “Security Warning” banner that states “Certain content in this
database has been disabled”, and there is a button labeled “Options” next to it.
This means that Access databases can contain code that can be executed on your computer. This code could be
something that you created and installed in the database, or if you downloaded the database from an un‐familiar
source, someone else could have created it. The question is “Do you trust the content of the database?”. If you do,
click on the “Options” button, choose “Enable this content”, and click “Ok”. If you do not trust the database,
choose “Help protect me from unknown content”. Be aware that if you choose this, some of the features of the
database may not work. Since we will be working with only databases that we create, we can choose to “Enable
this content”.
Overview of the Access Database Objects
The Objects
Don’t let the word “object” scare you, all it means is “thing”. Access has database objects, or database things,
which help you to store and manage your data.
Table – The table object is a storage type of an object. Your data is actually stored in a table. Tables are the
database. If you have no tables, there are no reasons to have forms, queries, or reports. You can have up to 32,000
tables in your Access database. A table in the “Datasheet” view is very similar to a worksheet in Excel. The
columns are called “fields” and the rows are called “records”.
Form – Forms are data‐entry objects. Forms are usually the main interface between the user and the database. When
entering data into a database, you should not enter data directly into a table; you should use a form to enter the data.
A form will enable you to enter data into more than one table at once. Forms can also display calculated fields. Look
in the “Concepts That You Need to Know” section for more information on calculated fields.
Prepared by moges tesfaye(MSC IN ICT)
Figure 8 - An Access Form
Query – A query is an output type of database object. A query is a custom view of your data. Queries enable you
to ask questions of the data in your tables. A query will enable you to combine data from many tables, up to 32
tables at once. A query is a type of filter that you can save with a name. You can have calculated fields in a
query also. Calculated fields are very powerful tools in Access.
Report – A report is another output type of database object. Reports are usually read‐only, formatted for easy
reading, and are meant to be printed. A report is usually based on a query. Whenever you run the report, the query
is executed, and the data returned from the query is passed to the report for presentation.
Macro – A macro is a series of actions that are saved with a name, and can be run at any time the user wishes.
Views
The database objects have different views in Access. They all have a normal view, which is the view that the
everyday user of the database uses, and they all have a design view, which is the view that the designer of the
database uses to modify the object. The user and the designer may be the same person, and they may not.
Entity – Information of importance about things involved in a business practice or process such as a customer, sale,
item, or employee. An entity is a major subject of a data model. Entities usually become tables in your database.
Associative Entity – An associative entity is an entity that associates two entities that are related in a many‐to‐
many type of a relationship. Associative entities usually become junction tables in your database. Associative
entities can be abstract objects, like registration, or schedule.
Attribute – An attribute is a factor or property of an entity, like the last name of a person. Person is the entity; last
name is an attribute of a person. Attributes will become fields in your tables.
Primary Key – A field or column in a table whose value uniquely identifies one record or row in a table. Each
table in your database should have a primary key.
Foreign Key – A foreign key is a non‐primary key in a table that relates a record (row) in one table to record in
another table. Foreign keys are the basis of relationships.
Relationship – A relationship is the association between two entities. There re three types of relationships:
many‐to‐many, one‐to‐many, and one‐to‐one.
Entity‐Relationship Diagram (ERD) – A diagram that shows the entities, attributes, primary keys, foreign keys,
and relationships, involved in a data model. ERDs are used in developing and refining database structure and
design.
Data Modeling
Overview
Data modeling is the practice of planning the logical foundation of your database. When designing a database in
Access, data modeling is planning and building tables, fields, keys, and relationships. You do not need to be a
computer scientist to build an Access database, although it does help to know the basics of relational database
theory. It also helps to have a big whiteboard, or at least some large sheets of paper.
There are five main steps to data modeling:
1. Identify entities
Each entity in your model will have attributes that you will want to record. Attributes describe entities and will
become fields in your tables.
The entities in your database will be related to each other in one of three ways. It is up to you to think of exactly
how they are related. Usually the way entities interact with each other in the real world is the way they should be
related in your database. For example, a truck can carry many shipments. A shipment could be carried on many
trucks (it may be a large shipment). So a truck entity could have a many‐to‐many relationship with a shipment
entity.
There are three types of relationships: one‐to‐one, one‐to‐many, and many‐to‐many. The one‐ to‐one relationship is
not used very much compared to the others. You will find many many‐to‐ many relationships. Access cannot
represent a many‐to‐many relationship, so you will need to solve the many‐to‐many relationship into two one‐to‐
many relationships using a junction table. Most of your relationships will be one‐to‐many, or many‐to‐many
relations converted to two one‐to‐many relations. More on this as we go.
Assign Primary and Foreign Keys
Relationships are implemented with keys. A key is an attribute or field in a table that is a unique identifier. A key is
unique to the record of which it is a part. A social security number is an example of a key. It is a unique identifier for
a person. No two people should have the same social security number. A vehicle registration tag number is a unique
identifier for a vehicle.
There are two basic types of keys: a primary key and a foreign key. A primary key is a field that is the main
unique identifier for an entity/table. A foreign key is a field in table that is not the primary key, but relates a record
in one table to a record in another table; it defines the association between entities, or tables.
Relationships
Getting Started
2. Point your mouse to Programs >> Microsoft Office >> Microsoft Access 2007.
Note: Access will force you to name this database file and save it before you do anything with it. This is
different from the other Office suite programs; they will let you work for hours and not save your work in a
file. When you are entering data to an Access database, Access saves each keystroke as you type it. This is
why you must save the file with a name and location from the beginning.
5. Enter the name for your new database in the “File Name:” box.
6. Click on the yellow file folder icon if you want to change the location to which your file will be saved.
Access opens your new blank database with a blank table in the Datasheet View. You can switch it to the
“Design View” by clicking on the “Home” tab, and then the “View” button, and then click on “Design
View”.
You can close the table by clicking on the “X” button on the right side.
If you are more familiar with the “Object Browser” look of the earlier versions of Access you may want to
switch the “Navigation Pane” to the “Object Type” view.
1. Click on the small black arrow at the top of the “Navigation Pane”.
Creating a Table
A table is a container for data. All of your data in Access 2007 will be stored in tables (columns are fields and
rows are records). Tables are the most important database objects in Access. You can create as many tables as you
Prepared by moges tesfaye(MSC IN ICT)
need. Usually you will have a table for each entity in your data model; see the “Database Design” section of this
document for more.
Template Tables
There are some template tables that are provided with Access 2007. One of these tables may be close to your
needs. If you choose to use a template table, you can modify it if you want.
1. Click on the “Create” tab, and then the “Table Templates” button.
If there are no template tables that suit your needs, you may want to create a table from “scratch”; this is
called creating a table in the “Design View”.
1. Click on the “Create” tab, and then the “Table Design” button.
A new table will open in the “Design View” and the “Design” contextual tab will open.
Data Type The type of data that is allowed into that field
(column). The data type can be used as a data
validation technique.
Description Informs the user what to enter in this field on the “Status
Bar”. Later, when you build a form for this table, as the data‐
entry user is tabbing from textbox control to textbox control,
the description will be displayed in the status bar at the
bottom left‐hand corner of the screen. You can think of the
description as instructions to the data‐entry user.
7. Press the “F6” key to move the cursor to the “Field Properties” area.
The “Field Properties” section changes to show the properties of the field that is selected. See below:
A primary key is a field that uniquely identifies each record in a table. There will never be duplicate data in
the primary key field.
1. With a table open in the design view, select the field which you want to set as a primary key.
2. Click the “Primary Key” button on the toolbar.
A composite primary key field is a combination of fields in which the fields together are unique. To set a composite
primary key:
1. With the table open in the design view, select one of the fields which will be part of the composite
primary key.
2. Hold down the “Ctrl” key and select the other keys which will be part of the composite primary key.
Prepared by moges tesfaye(MSC IN ICT)
3. Click on the “Primary Key” button.
A relationship is a means of relating data from one table, to data in another table. Access 2007 supports three
types of relationships: one-to-one, one-to-many, and many-to-many.
One-to-One One record in a table has one related record in another table.
One-to-Many One record in a table has many related records in another table. This is the
most common type of relationship.
Many-to-Many Many records in a table have many related records in another table. A third
table is required to do this. The third table is called a junction table. The other
two tables should be related to this junction table with two one-to-many
relationships.
Important: A relationship is implemented with a key pair: a primary key and a foreign key. Before tables can
be related, one of the tables should have a primary key, and the other table should have a foreign key. In other
words, the tables need to be designed so that they can be related. The data type of the foreign key must be
compatible with the data type of the primary key.
In the example above, the “CustomerID” foreign key in the “Sale” table will be used to relate a sale to a customer.
When a sale is made, the “CustomerID” foreign key field will hold the customer number that will relate the sale
to that customer.
1. Open the “Relationships” window by clicking on the “Database Tools” tab, and then the “Relationships”
button.
The first time you use the “Relationships” window, the “Show Tables” window opens also; use it to add
Prepared by moges tesfaye(MSC IN ICT)
the desired tables. If you ever need to add more tables to the “Relationships” window, click on the
“Show Table” button on the “Design” contextual tab.
2. Click on the foreign key, holding the mouse button down, and drag the foreign key over and drop it on
the primary key to which you wish.
3. The “Edit Relationship” window will open. Check the option to “Enforce Referential Integrity”.
By enforcing the relationship, Access will not allow a value to be entered in the foreign key field that does
not exist in the primary key field of the other table. It would not make sense to relate a sale to customer
number 47 if there were no customer number 47.
Note: If you try to make changes to a field that is a key participating in a relationship, you may have to delete
the relationship, make the change, and then re‐create the relationship.
To delete a relationship:
2. Choose “Delete”.
To edit a relationship:
Forms are used to add, edit, or view/display information in one or more tables at once. You should not enter
data directly into a table. If you have a simple database that consists of one table, you might be able to get away
with entering data directly into the table, but if you have more than one table, you should use a form.
The “Form Tool” will create simple forms for us almost instantly. It is good to use when you want to create a
form quickly. The “Form Tool” is smart; it can see the relationships to other tables and will create subforms
when needed.
To create a form for entering data into a table using the “Form Tool”:
1. Select the table that you want to build a form for by clicking on it one time. The example below uses the
“Employee” table.
Forms will be covered in greater detail in the Access 2007 Level 2 booklet and workshop.
Creating Forms
Forms are database objects that allow you to easily view, edit, or add data to one or more tables. A switchboard is a
type of form.
Forms are data‐entry tools. When a person enters data into a database he/she usually uses a form. A form is
designed in a user‐friendly manner that shows only one record at a time. When a record is edited in a form, the
record is actually changed in the table that is the record source for the form.
A form can also have a sub‐form that displays a one‐to‐many relationship between two tables and aids in the
creation of records in the table that is the record source for the sub‐form.
A switchboard is a type of form that is not used for data‐entry. Switchboards are used as a point of entry for a
database. A switchboard has labeled buttons, which, when clicked, will open a form, report, or perform some other
function.
Forms should be created only after the tables and relationships are created; with no tables, there is no need for
a form.
There are basically three methods of creating a form in Access 2007: with the form tool, with the form wizard,
and with the design view.
The form tool and the form wizard are pretty smart. If your tables and relationships are set up correctly, the form
tool and the form wizard will see the relationships and set up subforms for you. The form tool and the form wizard
are not smart enough to create calculated fields; you will have to do that yourself.
Creating a Form
1. Select the table on which you wish your form to be based. This action will set the new form’s “Record
Source” property to the table you select.
Note: Any form that you create with the form tool can be switched to the design view and modified.
To create a form with the Form Wizard:
1. Click on the “Create” tab, and then the “More Forms” button.
3. In the Tables/Queries section choose the table or query that will be the record source for your form.
4. In the “Available Fields” section, choose the fields that you wish to use from the table or query that you
selected in the previous step.
5. If you want your form to work with more than one table, go back and select the other table in the
Tables/Queries section, and then choose the fields that you want form that table.
6. Once you have all the fields from all the table or queries selected in the “Selected Fields” section,
click the “Next” button.
7. Click “Next”.
8. Click “Next”.
1. Click on the “Create” tab, and then click on the “Form Design” button.
A blank form opens; its record source property has not been set.
2. Set the “Record Source” property of the new form by clicking on the “Design” contextual tab,
and then click on the “Property Sheet” button.
3. Click in the “Record Source” property, then the drop‐down list to choose a table that you wish to be
the record source for this form. See Figure 5 ‐ Setting a Form's Record Source.
Note: Forms have many properties that can be set; the “Record Source” property is the most important one, it is
where the form is getting its data. Take the time to look through these properties while you can, it is beyond the
scope of this document to cover all of them.
Forms access data in tables through objects called controls. The default control is the textbox. If you created a form
with the form tool or the form wizard, fields from tables were added to the form for you as textboxes; these
textboxes are bound to the fields in the record source.
Forms created with the form tool or the form wizard can be opened in the design view to add more controls. If you
have created your form with the design view, it will not have any controls; you will need to add them yourself.
1. Open the desired form in the design view. If you just created a form in the design view, it is already open
in the design view. If the form is not open, you can right‐click on the form and choose “Design View”.
2. Click on the “Design” contextual tab, and then click on “Add Existing Fields” button.
3. Drag the desired fields from the field list over to the form and drop them on the form.
Note: You can select multiple fields by clicking on the first field and then hold the “Shift” key down a click
on the other fields.
A textbox will be installed on the form and the textbox will be bound to the field that you chose.
Text Box: The default control. When you add an existing field from a field list, a text box control is used by default.
A text box control comes with its own label control.
Combo Box: A drop‐down list type of control. A Combo Box control enables a user to choose from a list of
values. Lookups are implemented with Combo Box controls. The user can enter a value or choose from
the list. This function can be limited to list.
List Box: A list Box enables the user to choose from a list, but the list stays open and is not in a drop‐down.
Subform/Subreport: A subform shows information from another table, usually a table that has records related to
the main form in a one‐to‐many relationship.
Line: A Line is a drawing tool; it enables you to draw a line on your form.
Rectangle: A Rectangle is a drawing tool; it enables you to draw a rectangle on your form.
Bound Object Frame: A control that enables you to put an image on a form
Option Group: A group of Check Boxes or Option buttons that gives the user an option of values that can be
chosen. Check boxes, option buttons, and toggle buttons, can be used as members of option groups.
Tab Control: Helps to save space on a form. A Tab control enables more controls in the same amount of space.
Adding Controls to a Form
2. Click on the “Design” contextual tab. You should see a “Controls” section of the “Design” ribbon.
4. Click on the form in the area in which you wish to place the new control.
Note: Some of the controls have a wizard that will help you setup the control to operate in the manner you desire;
these wizards will only run when the “Use Control Wizards” button is toggled on. You will find this button on the
“Design” contextual tab when you have a form open in the design view.
Often, you will need to move a control on a form in order to prevent obscuring another control, or re‐size a control
so that it better fits the data that is to be displayed.
When you add individual controls (or drag fields) to a form, you can move the control by first clicking it to
select it, and then pointing at the border of the control until the mouse pointer changes to a four‐headed arrow
and dragging.
An alternate and more precise way of moving a control is to use the directional arrow keys on your keyboard,
rather than clicking and dragging. By holding down the CTRL key as press the directional arrows, you can move
the control in very small increments.
In the example above, when you move either the text box or its associated label, the other control moves, as
well.
To move either of these controls separately, place your mouse pointer over the small square at the top left corner of
the control (the “move handle”), and then click and drag.
If you use the Form Tool or the Form Wizard to create a form, the controls will be bound together in a “layout”.
Before you can move any of the controls individually, you will have to remove the layout. To remove the
layout:
1. Hold down the SHIFT key and click on each of the controls that you want to separate.
Re‐sizing:
If several controls are bound together in a layout, re‐sizing one control will re‐size all the controls. Sometimes this
A Subform can be a very useful control; it enables you to display information from another table that is related to
the information on the main form in an intuitive one‐to‐many manner. A subform enables you to work with data
in more than one table at once.
2. Click on the “Design” contextual tab, and then the “Subform/Subreport” button.
3. Move your mouse cursor over the form and you will notice that it has changed to an image of a
subform.
4. Click on the form in the area where you wish to install the subform.
If you have the “Use Control Wizards” button toggled on, the subform wizard will start; it will help
you to setup the new control.
If you do not have the “Use Control Wizards” button toggled on, you will need to set the record source
property manually; refer to the section on creating a form in the design view for details on selecting a
form/subform and setting the record source property.
The example above shows a subform created from a table. You may prefer to add a subform by first creating a
separate form to use as the subform, and then selecting that form as you go through the SubForm Wizard. This
method allows you to produce a subform with the same color scheme as your main form.
Using the Switchboard Manager
A switchboard is a type of form that is intended to be a starting point for the users of a database. A switchboard
is a tool that enables the database designer to simplify the use of a database by only showing tasks that the user
performs on a regular basis. There can be many objects in an Access database; some of these objects are never
intended for use by “everyday” users of the database, the switchboard enables the designer to hide these objects
and only show the ones wanted.
The forms in your database are usually task‐oriented. For example, if you wanted to add a new employee to the
“Employee” table, you would open the “Employee” form to enter the information. If you wanted to add a new
item to the “Item” table, you would open the “Item” form to enter the information about the new item. If you
want to record a sale you would open the “Record a Sale” form to enter information to the “Customer” table, the
“Sale” table, and the “Sale Item” table. The switchboard gives you a one‐stop access to these tasks.
When you get ready to create the switchboard, you need to have already created the data‐ entry forms for
your database.
To create a switchboard:
3. The “Switchboard Manager” will open, there is already one switchboard listed, we want to edit it. Click
the “Edit” button.
4. Note: You can have many switchboards, if you have a large database, you will probably have many
everyday tasks. You can link to a switchboard from the main switchboard if you like. In the sample
exercise we only have three main tasks for now, so we don’t need but one switchboard, the main
switchboard.
6. For each item that you add to the page, there will be a button with a label, in the “Text:” section, enter
the text that you wish to appear next to the button for this item. This text should describe the task, for
example, “Add/View/Edit an Employee”.
7. In the “Command:” section, choose the type of action you wish to occur when you click on the button.
For example, in this case, you want the “Employee” form to open when someone clicks on the button.
8. When we choose “Open Form in Edit Mode”, the last section of the window changes to enable us to
choose the desired form, in this case, the “Employee” form.
10. Repeat steps 5 through 9 for each item on this switchboard page.
4. In the “Application Options” section, set the “Display Form:” option to “Switchboard”.
A query can return all of the data from one or more tables, or it can be designed to summarize data, filter by
criteria, and/or include calculated fields.
Types of Functions
Queries
Retrieves data from one or more tables and displays the results in a
Select datasheet. When you create a query in Access, it is by default a Select
Query.
You can create queries using the query design grid (design view), or by using one of the four query wizards. Once
you create a select query, you can then modify it by adding criteria to find the specific data that you want. Also,
you can modify any query that you create using a wizard by opening it in the design view.
Note: The examples in this section are accessible in the computer labs on campus on the P: drive at P:\\Training\
Access 2007\Level 3\pet.accdb database.
Creating a Query with the Wizard
To create a query, you must have at least one table containing data. A query can create a view from one or more
tables; up to 32 tables maximum. We will create a select query that brings together fields from two tables. A
select query can be used as a record source for a report, or even a mail merge from Microsoft Word. By default
the query wizard creates a select query.
1. Click on the “Create” tab, and then the “Query Wizard” button.
3. Click “OK”.
5. Click “Next”.
6. If you selected fields from more than one table, you will be asked to choose “Detail” or “Summary”. A
detail query will return every record of the many side of a one-to-many relationship. A summary query
will return records based on the one side of a one-to- many relationship.
7. If you choose the “Summary” query, click on the “Summary Options” to select the type of summary you
wish: sum, avg., min, or max.
8. Click “OK”.
9. Click “Next”.
When you create a query that involves fields from two tables, and those tables are related in a one-to-many
manner, you can choose a detail query or a summary query. A detail query is focused on the many-side of the
relationship, where the summary query is focused on the one- side.
The following images are the results returned from two queries where the only difference between the two
is that one query is a detail query and the other is a summary query.
The 4 fields in the two queries above are from two tables that are related with a one‐to‐many relationship: the
Customer table (one‐side) and the Order table (many‐side).
Notice that in Figure 2, the detail query, the 1 field from the one‐side (Customer Name) is repeated for every
record in the many‐side (OrderNumber, TotalInvoice, and AmountPaid).
Notice that in Figure 3, the summary query, the 1 field from the one‐side of the relation (Customer Name) is listed
only once and the fields from the many‐side of the relation are summarized or totaled.
In summary, a detail query is focused on the many‐side of a one‐to‐many relationship, and a summary query is
focused on the one‐side and summarizes the information from the many‐side of the relationship.
The query wizard works well; it enables you to easily choose the fields that you want included in your query,
build a subform if your fields are from two or three related tables, and choose either the detail or summary mode,
but that is all it will do. If you want to enter filter criteria, create calculated fields, or create an action query, you
will need to create your query in the design view.
Note: You can create a query with the wizard and then switch the query to the design view to make changes if you
like (click on the “Home” tab, and then the “View” button).
1. Click on the “Create” tab, and then the “Query Design” button.
2. The “Query Design Grid” will open and the “Show Table” window opens also.
3. Using the “Show Table” window, choose the tables that contain the fields you want to see or use in your
query.
5. Click on the fields that you want in your query and drag them down to the grid and drop them.
Once you have added the fields that you want to your query you can run (execute) the query by
clicking on the “Run” button on the “Query Tools” contextual tab.
If you run the query as it is now, it will return all the records involved because we have not set any criteria.
We will also need to change the query to a summary query because by default queries are detail select
queries.
2. Click on the “Query Tools” contextual tab, and then the “Totals” button.
4. To work properly as a summary query, every field from the “Order” table should have a value of
something other than “Group By” in the “Total:” row.
5. We can change the “TotalInvoice” and “AmountPaid” to “Sum” in the “Total:” row.
Name Description
Field Lists the name of a field or calculated field that needs to be included in
the query.
Table Displays the name of the table that the field comes from.
Sort Enables the user to sort the field in ascending or descending order.
Show Enables the user to display or hide the field when the query is
run.
Criteria Informs Access of the criteria for the field in the same column.
Some fields in your database should not be recorded in a table, but calculated from information recorded in a table.
A good example of this is a person’s age. You do not want to record a person’s age in your database because it
changes every year; next year it would be incorrect.
You want to record the person’s birth date; it never changes. When you need to see the person’s age in a
In the query shown in Figure 6 below, the “BalanceDue” field is calculated by subtracting the “AmountPaid”
from the “TotalIvoice” fields.
Note: Notice the colon between the name of the calculated field and the expression; it acts as an equal sign.
When this query is executed, the results will appear as in the image below.
Note: Calculated fields are very powerful tools. They are mainly created using expressions. There is a very good
section of the “Help” feature in Access 2007. Open “Help” and search for “Introduction to Expressions”
Adding Filtering Criteria to a Query
A select query (detail or summary) simply displays fields from one or more tables in the database; it will return all
records containing the chosen fields. Often, you’ll need to add criteria to a query to filter out records that you do
not want to see. You can use filter criteria to limit the records returned so that only the information you want to see
is returned when the query is executed. To add criteria to a query, open the query in the “Design View” and enter
the text or numbers that define the criteria into the Criteria row in the appropriate field.
The purpose of the query shown in Figure 8 above is to return a list of customers that owe money. Well, one
customer owes $1.74. If we only want to see records where the balance due is greater than 10 dollars we can add
the criteria above “>10”.
Note: Query criteria are very powerful tools. They are mainly created using expressions. There is a very good
section of the “Help” feature in Access 2007. Open “Help” and search for “Examples of Query Criteria”.
Action Queries
An action query is a query that makes changes to one or many records in just one operation. There are four types
of action queries: update, delete, append, and make table. Action queries can save time by performing mass
updates or deletes.
Note: Since update and delete queries may cause violations of referential integrity between some tables, it may
be necessary to remove referential integrity, or sever the relationship between the tables, before the query
action can be completed.
Note: To create any of the action queries, start by creating a regular select query first then you can change the
query to one of the action query types.
Warning: The use of action queries may result in unintended changes to you data. Make a copy of your database
and practice on a copy until you are very familiar with the results.
Update Query
An update query will allow you to perform mass updates depending on the criteria you specify. For instance, you
might want to increase the prices of the items you sell by 10 percent. An update query makes updating groups of
records quick and efficient, saving you the time and effort of doing each update individually.
1. Create a new query in design view by clicking on the “Create” tab, and then the “Query Design” button.
3. Select the fields you want to update or use in the criteria by dragging them down to the query grid; in this
case, the “CurrentPrice” field.
4. Click on the “Design” contextual tab, and then the “Update” button.
The query design grid will now change to show an “Update To:” row.
5. Enter an expression into the “Update To:” cell for the field that you wish to update, that will result in the
change that you wish. For example, if we want to increase the “CurrentPrice” field by 10 percent, we
would enter: “[CurrentPrice] + ([CurrentPrice]*0.01)” or “[CurrentPrice]*1.01”.
7. You should see a warning message that indicates you are about to update rows in your table(s). Click
“Yes” to complete the action.
8. If the update is successful, you will see no error message; your data has been updated. You will need to
open the table to inspect the results.
A delete query will allow you to perform mass record deletions depending on the criteria you specify. Delete
Prepared by moges tesfaye(MSC IN ICT)
queries are the most dangerous of all the action queries. A delete query will delete your data permanently.
In the normal operation of a database there is seldom a need to delete data; the object is to save the data.
Sometimes if you are importing data from another source you may need to “massage” the contents before using
it in your database.
1. Create a new query in design view by clicking on the “Create” tab, and then the “Query Design” button.
3. Select the fields you want to use as criteria by dragging them down to the query grid.
4. Click on the “Design” contextual tab, and then the “Delete” button.
The query design grid will now change to show a “Delete:” row.
5. Enter an expression into the “Delete:” cell for the field that you are using as criteria, which will result
in the change that you wish.
10. You should see a warning message that indicates you are about to delete rows in your table(s). Click
“Yes” to complete the action.
6. If the deletion is successful, you will see no error message; your data has been deleted. You will need to
open the table to inspect the results.
Append Query
An append query adds a group of records from one or more tables to the end of one or more tables.
Note: The records that are being appended cannot contain fields that do not exist in the receiving table. Also, the
names and data types of the corresponding fields in both tables must be the same.
1. Create a new query in design view by clicking on the “Create” tab, and then the “Query Design”
button.
3. Select the fields you want to be appended to the destination table by dragging and dropping
them to the grid.
4. Click on the “Design” contextual tab, and then the “Append” button.
5. In the “Append” dialog box, enter or choose the name of the table into which the records
will be appended, and click “OK”.
An “Append To:” row is added to the query grid that contains the names of the fields in the table
into which the records will be appended.
6. Add any filter criteria that you may need to exclude records that should not be
appended.
8. You should see a warning message that indicates you are about to append rows. Click “Yes” to
complete the action.
9. If the append is successful, you will see no error message; your data has been
appended. You will need to open the table to inspect the results.
A make table query creates a separate new table using the results of the query. To create
a make table query:
1. Create a new query in design view by clicking on the “Create” tab, and then the “Query Design”
button.
3. Select the fields you want to be included in the new table by dragging and dropping them to
the grid.
4. Click on the “Design” contextual tab, and then the “Make Table” button.
5. In the “Make Table” dialog box, enter the name you wish for the new table. If you want the new
table to go into a different database, click the “Another Database” option button, and enter the
path to, or browse to that database file.
6. Click “OK”.
7. Add any filter criteria that you may need to exclude records that should not be included in the new
table.
8. Click the “Run” button on the “Design” contextual tab to execute the query.
9. You should see a warning message that indicates you are about to paste rows into a new
table. Click “Yes” to complete the action.
10. If the operation is successful, you will see no error message; your table has been created.
You will need to open the table to inspect the results.
Parameter Queries
A parameter query prompts the user to enter query filter criteria when it is run, thus giving a great deal of
flexibility to a single query. For example, if you create a query that will show sales for a date, you will
have to change that query if you want to see sales for a different date. You can easily end up with many
queries this way. If you create a query that asks you for a range of dates when it is run, you can have the
same functionality with just one query.
1. Create a new query in the design view by clicking on the “Create” tab, and then the “Query
Design” button, or open an existing query in the design view.
2. Add the table that is the source of records to be included in the new table using the show
Prepared by moges tesfaye(MSC IN ICT)
table window.
3. Select the fields you want to be included in the new table by dragging them from the table
field list and dropping them to the grid.
4. Enter an expression into the “Criteria” row for one of the fields that you selected. In the
expression, substitute a parameter for any values needed. See the example below.
In the query example above, when executed, this query will stop and ask the user for a “Start
Date” and then a “Finish Date”. The dates entered by the user will be substituted into the criteria
expression and then the query will be executed.
5. Click the “Run” button on the “Design” contextual tab to execute the query.
7. Click “OK”.
A report is usually a read only view of information in a database. Reports are mainly designed to be
printed. A report’s record source property can be either a table or a query.
The easiest method of creating a report is using the report wizard. The wizard will get you close to the
report that you want and you can switch the report to the design view to modify it with any changes that
you prefer.
1. Click on the “Create” tab, and then the “Report Wizard” button.
The report wizard is not much different from the other wizards in Access. The first thing that it
helps you to do is set the record source for the report and to choose the fields that you want to use
on the report.
2. Choose the fields that you would like to see on your report. You can choose fields from one or
more tables.
3. Click “Next”.
4. Choose the view that you would like for your report. Usually the default setting is best here.
5. Click “Next”.
6. If you chose fields from more than one table, there will probably already be some
grouping. If would like to set additional grouping levels do so here, and then click “Next”.
7. On this screen you can sort or summarize fields on your report. Click “Next”.
8. Make changes to the layout if you wish, and then click “Next”.
10. On the last screen, you can set the name of the report, and then click “Finish”.
A macro is a series of commands and instructions that you group together as a single command to
accomplish a task automatically. Macros can be beneficial for performing repetitive tasks. A macro is
actually Visual Basic code, and, as such, is different than other database objects.
4. Click the Action drop‐down, and select the first action that you want to perform. (Actions will
be performed in the order in which they are listed in the Macro window.)
5. Repeat the above process until you have added all necessary actions.
To run the macro, click the Run button. After the macro has been closed, run it by double‐clicking the macro in the
Objects Bar. To open the macro in Design View, right‐ click the macro in the Objects Bar and select “Design View”
from the shortcut menu.