0% found this document useful (0 votes)
55 views

Database Management Systems (DBMS) Using Microsoft Office 2007

The document discusses database management systems (DBMS) and Microsoft Access. It defines a DBMS as software used to create, define, maintain and control databases. It then lists advantages and disadvantages of DBMS, examples of DBMS software including Microsoft Access, and components of a database including hardware, software, data, procedures and people. It also describes database objects in Access like tables, queries, forms and reports.

Uploaded by

David Lwanga
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Database Management Systems (DBMS) Using Microsoft Office 2007

The document discusses database management systems (DBMS) and Microsoft Access. It defines a DBMS as software used to create, define, maintain and control databases. It then lists advantages and disadvantages of DBMS, examples of DBMS software including Microsoft Access, and components of a database including hardware, software, data, procedures and people. It also describes database objects in Access like tables, queries, forms and reports.

Uploaded by

David Lwanga
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

COMEDS COMPUTER CENTRE

DATABASE MANAGEMENT SYSTEMS (DBMS)


Using Microsoft office 2007
Database management system is a software that is used to define, create, create maintain and
control database

A database is a common data pool maintained to support the various activities taking place within an
organization

A database can also be defined as an organized set of data items that reduces duplicates of stored
records, unlike integrated file systems in which case several interdependent files are maintained for
different user requirement

Advantages of Database Management Systems

1. Collection of files are grouped together as one entity


2. Avoid duplication of file (Avoid data redundancy)
3. Improved Security
4. Use of integrated systems is greatly facilitated.
5. Improved data accessibility and responsiveness
6. Improved data integrity
7. Sharing of Data
8. Data consistency

Disadvantages of Database Management Systems

1. Its size, its cost and time required to implement such a system
2. A large full time staff is also required in program support and implementation

Examples of database software’s

1. Microsoft Access
2. D base
3. Fox Pro
4. SQL ( Structured Query Language)

COMPONENTS OF DATABASE

1. Hardware – Includes computers, Memory etc.


2. Software – It comprises Database Management software itself and the application programs
and OS.
3. Data – Contains both Operational data and Network data.
4. Procedures – They refer to the instructions and rules that govern the design and use of the
database.
5. People – The final component is the people involved with the system

Ms Access DATABASE OBJECTS

1. Tables
2. Queries
3. Forms
4. Reports
5. Macros
6. Modules
7. Pages
1
FEATURES OF GOOD DATABASE

Divides your information into subject-based tables to reduce redundant data.

Provides Access with the information it requires to join the information in the tables together as

needed.

Helps support and ensure the accuracy and integrity of your information.

Accommodates your data processing and reporting needs.

Create a blank database

1. On the Getting Started with Microsoft Office Access page, under New Blank Database, click

Blank Database.

2. In the Blank Database pane, type a file name in the File Name box. If you do not supply a file

name extension, Access adds it for you. To change the location of the file from the default, click

Browse for a location to put your database (next to the File Name box), browse to the new

location, and then click OK.

3. Click Create.

DEFINATION OF TERMS
Each row is also called a record, and each column, is also called a field. A record is a meaningful and consistent
way to combine information about something. A field is a single item of information — an item type that appears
in every record. In the Products table, for instance, each row or record would hold information about one product.
Each column or field holds some type of information about that product, such as its name or price

TABLES

A table contains data about a particular subject, such as employees or products. Each record in a table contains

information about one item, such as a particular employee. A record is made up of fields, such as name, address

and telephone number. A record is also commonly called a row, and a field is also commonly called a column.

Create a new table

A simple database, such as a contact list, might use only a single table. Many databases, however, use several

tables. When you create a new database, you create a new file on your computer that acts as a container for all

of the objects in your database, including your tables.

When you create a new blank database, a new empty table is automatically inserted for you. You can then enter

data to start defining your fields.

2
Create a new table in a new database

1. Click the , and then click New.

2. In the File Name box, type a file name. To change the location, click the folder icon to browse.

3. Click Create.

The new database is opened, and a new table named Table1 is created and opened in Datasheet view.

Add a new field to an existing table

1. Click the , and then click Open.

2. In Open dialog box, select and open the database.

3. In the Navigation Pane, double-click one of the available tables to open it.

4. Type your data in the cell below the Add New Field column header.

Add a new field to a new table

1. Click the , and then click Open.

2. In Open dialog box, select and open the database.

3. On the Create tab, in the Tables group, click Table.

4. Type your data in the cell below the Add New Field column header.

PRIMARY KEY

The primary key of a table consists of one or more fields that uniquely identify each row you store in the table.

Often, there is a unique identification number, such as an ID number, a serial number, or a code, that serves as

a primary key. For example, you might have a Customers table where each customer has a unique customer ID

number. The customer ID field is the primary key of the table.

A good candidate for the primary key has several characteristics. First, it uniquely identifies each row. Second, it

is never empty or null — there is always a value. Third, it rarely (ideally never) changes. Access uses primary

key fields to quickly bring together data from multiple tables.

You should always specify a primary key for a table. Access automatically creates an index for the primary key,

which helps speed up queries and other operations. Access also ensures that every record has a value in the

primary key field, and that it is always unique.

3
When you create a new table in Datasheet view, Access automatically creates a primary key for you and assigns

it a field name of ID and the AutoNumber data type. The field is hidden in Datasheet view, but you can see it if

you switch to Design view.

Set or change the primary key

1. Open the table in Design view.

2. Select the field or fields you want to use as the primary key.

To select one field, click the row selector for the field you want.

To select more than one field, hold down the CTRL key and then click the row selector for each field.

3. On the Design tab, in the Tools group, click Primary Key.

A key indicator is added to the left of the field or fields that you specify as the primary key.

Remove the primary key

1. Open the table in Design view.

2. Click the row selector for the current primary key.

If the primary key consists of a single field, click the row selector for that field.

If the primary key consists of multiple fields, click the row selector for any field in the primary key.

3. On the Design tab, in the Tools group, click Primary Key.

4
DATA TYPES

Data type Stores Size

Text Alphanumeric characters Up to 255 characters.

Use for text, or text and numbers that are not used in
calculations (for example, a product ID).

Memo Alphanumeric characters (longer than 255 characters in Up to 1 gigabyte of characters, or 2 gigabytes of storage (2 bytes
length) or text with rich text formatting. per character), of which you can display 65,535 characters in a
control.
Use for text greater than 255 characters in length, or for
text that uses rich text formatting. Notes, lengthy
descriptions, and paragraphs with formatting such as bold
or italics are good examples of where you would use a
Memo field.

Number Numeric values (integers or fractional values). 1, 2, 4, or 8 bytes, or 16 bytes when used for replication ID.

Use for storing numbers to be used in calculations, except


for monetary values (use the Currency for data type for
monetary values).

Date/Time Dates and times. 8 bytes.

Use for storing date/time values. Note that each value


stored includes both a date component and a time
component.

Currency Monetary values. 8 bytes.

Use for storing monetary values (currency).

AutoNumber A unique numeric value that Office Access 2007 4 bytes or 16 bytes when used for replication ID.
automatically inserts when a record is added.

Use for generating unique values that can be used as a


primary key. Note that AutoNumber fields can be
incremented sequentially, by a specified increment, or
chosen randomly.

Yes/No Boolean values. 1 bit (8 bits = 1 byte).

Use for True/False fields that can hold one of two possible
values: Yes/No or True/False, for example.

OLE Object OLE objects or other binary data. Up to 1 gigabyte.

Use for storing OLE objects from other Microsoft Windows


applications.

Attachment Pictures, Images, Binary files, Office files. For compressed attachments, 2 gigabytes. For uncompressed
attachments, approximately 700k, depending on the degree to
This is the preferred data type for storing digital images which the attachment can be compressed.
and any type of binary file.

Hyperlink Hyperlinks. Up to 1 gigabyte of characters, or 2 gigabytes of storage (2 bytes


per character), of which you can display 65,535 characters in a
Use for storing hyperlinks to provide single-click access to control.
Web pages through a URL (Uniform Resource Locator) or
files through a name in UNC (universal naming convention)
format. You can also link to Access objects stored in a
database.

Lookup Wizard Not actually a data type; instead, this invokes the Lookup Table or query based: The size of the bound column.
Wizard.

5
Use to start the Lookup Wizard so you can create a field Value based: The size of the Text field used to store the value.
that uses a combo box to look up a value in another table,.

FIELD PROPERTIES

You can control the appearance of information, prevent incorrect entries, specify default values, speed up

searching and sorting, and control other appearance or behavior characteristics by setting field properties. For

example, you can format numbers to make them easier to read, or you can define a validation rule that must be

satisfied for information to be entered in a field.

The data type of the field determines the properties you can set. For example, the AppendOnly property applies

only to a field that is set to the Memo data type. You cannot set this property on a field with any other data type.

Access uses the field property settings when you view and edit data. For example, the Format, InputMask, and

Caption properties affect how your information appears in table and query datasheets. In addition, any controls

on new forms and reports that are based on the fields in the table inherit these same property settings by default.

You use other properties to set a default value for a field or to require a user to enter a value, which Access

enforces whenever you add or edit data in the table.

Set a field property for a table in Datasheet view


1. Open the table in Datasheet view.

2. Click in the field for which you want to set the property.

3. On the Datasheet tab, in the Data Type & Formatting group, select one of the following
commands:

4.

 Unique — Sets the Indexed property.

 Is Required — Toggles the setting of the Required property. If it was set to Yes, it is
set to No. If it was set to No, it is set to Yes.

You can set only a few of the available field properties in Datasheet view. To set additional field
properties, you must open the table in Design view.

To have access to and set the complete list of field properties, you must use Design view.

Set a field property for a table in Design view


1. Open the table in Design view.

2. In the upper portion of the table design grid, click the field for which you want to set properties (or
move to the field by using the arrow keys).

3. Access displays the properties for this field in the lower portion of the table design grid. The data
type of the field determines the properties you can set.

4. In the lower portion of the window, under Field Properties, click the box for the field property you
want to set. Alternatively, you can press F6 and then move to the property by using the arrow keys.

6
5. Type a setting for the property or, if an arrow appears at the right side of the property box, click the
arrow to choose from a list of settings for the property.

The following table lists the available field properties.

Use this field


property To

FieldSize Set the maximum size for data stored as a Text, Number, or AutoNumber data type.

Format Customize the way the field appears when displayed or printed.

DecimalPlaces Specify the number of decimal places to use when displaying numbers.

NewValues Set whether an AutoNumber field is incremented or assigned a random value.

InputMask Display editing characters to guide data entry.

Caption Set the text displayed by default in labels for forms, reports, and queries.

DefaultValue Automatically assign a default value to a field when new records are added.

ValidationRule Supply an expression that must be true whenever you add or change the value in this field.

ValidationText Enter text that appears when a value violates the ValidationRule expression.

Required Require that data be entered in a field.

AllowZeroLength Allow entry (by setting to Yes) of a zero-length string ("") in a Text or Memo field.

Indexed Speed up access to data in this field by creating and using an index.

UnicodeCompression Compress text stored in this field when a large amount of text is stored (> 4,096 characters)

IMEMode Control conversion of characters in an Asian version of Windows.

IMESentenceMode Control conversion of characters in an Asian version of Windows.

SmartTags Attach a smart tag to this field.

AppendOnly Allow versioning (by setting to Yes) of a Memo field.

TextFormat Choose Rich Text to store text as HTML and allow rich formatting. Choose Plain Text to store only
text.

TextAlign Specify the default alignment of text within a control.

Precision Specify the total number of digits allowed, including those both to the right and the left of the
decimal point.

Scale Specify the maximum number of digits that can be stored to the right of the decimal separator.

If you want more space to enter or edit a property setting in the property box, press SHIFT+F2 to

display the Zoom box. If you are entering an input mask or validation expression and would like help in

building it, click next to the property box to display the appropriate builder.

7
The following table provides additional information about the FieldSize, Format and New Values field properties

dSize property Description

Text Enter a value from 1 to 255. Text fields can range from 1 to 255 characters. For larger text fields,
use the Memo data type.

Number Select one of the following:

Byte — For numeric values that range from 0 to 255. Storage requirement is a
single byte.

Integer — For numeric values that range from -32,768 to +32,768. Storage
requirement is two bytes.

Long Integer — For numeric values that range from -2,147,483,648 to


+2,147,483,647. Storage requirement is four bytes.

TIP   Use Long Integer for storing as a foreign key the value that appears in another
table's primary key AutoNumber field.

Single — For numeric floating point values that range from -3.4 x 1038 to +3.4 x
1038 and up to seven significant digits. Storage requirement is four bytes.

Double — For numeric floating point values that range from -1.797 x 10308 to
+1.797 x 10308 and up to fifteen significant digits. Storage requirement is eight bytes.

Replication ID — For storing a globally unique identifier required for replication.
Storage requirement is sixteen bytes. Note that replication is not supported using the
.accdb file format.

Decimal — For numeric values that range from -9.999... x 1027 to +9.999... x 1027.
Storage requirement is twelve bytes.

AutoNumber Select one of the following:

Long Integer — For unique, numeric values that range from 1 to +2,147,483,648
when the New Values field property is set to Increment, and -2,147,483,648 to
+2,147,483,647 when the New Values field property is set to Random. Storage
requirement is four bytes.

Replication ID — For storing a globally unique identifier required for replication.
Storage requirement is sixteen bytes. Note that replication is not supported using the
.accdb file format.

Format property

Text You can define a custom format. For more information, see Format data in tables, forms, and
reports.

Date/Time Select one of the following predefined display formats:

General Date — Displays the value using a combination of the Short Date and
Long Time settings.

Long Date — Displays the value using the Long Date setting from the Regional and
Language Options settings in the Control Panel.

Medium Date — Displays the value using the format dd-mmm-yy (14-Jul-06, for
example).

Short Date — Displays the value using the Short Date setting from the Regional
and Language Options in the Control Panel.

Long Time — Displays the value using the Time setting in the Regional and
Language Options in the Control Panel.

8
Medium Time — Displays the value using the format HH:MM PM where HH is the
hour, MM is the minute, and PM is either AM or PM. The hour can range from 1 to 12. The
minute can range from 0 to 59.

Short Time — Displays the value using the format HH:MM where HH is the hour
and MM is the minute. The hour can range from 0 to 23 and the minute from 0 to 59.

Yes/No Select one of the following:

 True/False — Displays the value as either True or False.

 Yes/No — Displays the value as either Yes or No.

 On/Off — Displays the value as either On or Off.

 NOTE    In the above, On, True and Yes are equivalent. False, No and Off are also equivalent.

New Values property

AutoNumber Select one of the following (for the AutoNumber data type only):

 Increment — Start value at 1 and increment by 1 for each new record.

 Random — Start

Types of table relationships


There are three types of table relationships.

A one-to-many relationship

Consider an order tracking database that includes a Customers table and an Orders table. A customer
can place any number of orders. It follows that for any customer represented in the Customers table,
there can be many orders represented in the Orders table. The relationship between the Customers
table and the Orders table is, therefore, a one-to-many relationship.

To represent a one-to-many relationship in your database design, take the primary key on the "one"
side of the relationship and add it as an additional field or fields to the table on the "many" side of the
relationship. In this case, for example, you add a new field — the ID field from the Customers table — to
the Orders table and name it Customer ID. Access can then use the Customer ID number in the Orders
table to locate the correct customer for each order.

A many-to-many relationship

Consider the relationship between a Products table and an Orders table. A single order can include
more than one product. On the other hand, a single product can appear on many orders. Therefore, for
each record in the Orders table, there can be many records in the Products table. In addition, for each
record in the Products table, there can be many records in the Orders table. This type of relationship is
called a many-to-many relationship because, for any product, there can be many orders and, for any
order, there can be many products. Note that to detect existing many-to-many relationships between
your tables, it is important that you consider both sides of the relationship.

To represent a many-to-many relationship, you must create a third table, often called a junction table,
that breaks down the many-to-many relationship into two one-to-many relationships. You insert the
primary key from each of the two tables into the third table. As a result, the third table records each
occurrence, or instance, of the relationship. For example, the Orders table and the Products table have
a many-to-many relationship that is defined by creating two one-to-many relationships to the Order
Details table. One order can have many products, and each product can appear on many orders.

A one-to-one relationship

In a one-to-one relationship, each record in the first table can have only one matching record in the
second table, and each record in the second table can have only one matching record in the first table.

9
This type of relationship is not common because, most often, the information related in this way is
stored in the same table. You might use a one-to-one relationship to divide a table with many fields, to
isolate part of a table for security reasons, or to store information that applies only to a subset of the
main table. When you do identify such a relationship, both tables must share a common field.

Why create table relationships?


You can create table relationships explicitly by using the Relationships window, or by dragging a field from the
Field List pane. Office Access 2007 uses table relationships to how to join tables when you need to use them in
a database object. There are several reasons why you should create table relationships before you create other
database objects, such as forms, queries and reports.

Table relationships inform your query designs

To work with records from more than one table, you often must create a query that joins the tables. The
query works by matching the values in the primary key field of the first table with a foreign key field in
the second table. For example, to return rows that list all of the orders for each customer, you construct
a query that joins the Customers table with the Orders table based on the Customer ID field. In the
Relationships window, you can manually specify the fields to join. However, if you already have a

relationship defined between the tables, Office Access 2007 supplies the default join, based on existing
the table relationship. In addition, if you use one of the query wizards, Access uses the information it
gathers from the table relationships you have already defined to present you with informed choices and
to prepopulate property settings with appropriate default values.

Table relationships inform your form and report designs

When you design a form or report, Office Access 2007 uses the information it gathers

Referential integrity
The purpose of referential integrity is to to prevent orphans and keep references in sync so that this hypothetical
situation never occurs

You enforce referential integrity by enabling it for a table relationship (see Enforce referential integrity for step-by-
step instructions). Once enforced, Access rejects any operation that would violate referential integrity for that
table relationship. This means Access will reject both updates that change the target of a reference, and
deletions that remove the target of a reference

View table relationships

To view your table relationships, click Relationships on the Database Tools tab. The Relationships window
opens and displays any existing relationships. If no table relationships have yet been defined and you are
opening the Relationships window for the first time, Access prompts you to add a table or query to the window.

Open the Relationships window

1. Click the Microsoft Office Button , and then click Open.

2. In the Open dialog box, select and open the database.

3. On the Database Tools tab, in the Show/Hide group, click Relationships.

4. If the database contains relationships, the Relationships window appears. If the database does not
contain any relationships and you are opening the Relationships window for the first time, the Show
Table dialog box appears. Click Close to close the dialog box.

10
5. On the Design tab, in the Relationships group, click All Relationships

The primary key

This line represents the relationship

The foreign key

A table relationship is represented by a relationship line drawn between tables in the Relationships window. A
relationship that does not enforce referential integrity appears as a thin line between the common fields
supporting the relationship. When you select the relationship by clicking its line, the line thickens to indicate it is
selected. If you enforce referential integrity for this relationship, the line appears thicker at each end. In addition,
the number 1 appears over the thick portion of the line on one side of the relationship, and the infinity symbol (∞)
appears over the thick portion of the line on the other side.

You can select from the following commands on the ribbon when the Relationships window is active:

On the Design tab, in the Tools group:

 Edit Relationships  Opens the Edit Relationships dialog box. When you select a relationship line,
you can click Edit Relationships to change the table relationship. You can also double-click the
relationship line.

 Clear Layout  Removes all tables and relationships from display in the Relationships window. Note
that this command only hides the tables and relationships — it does not delete them.

 Relationships Report  Creates a report that displays the tables and relationships in your
database. The report shows only the tables and relationships that are not hidden in the Relationships
window.

On the Design tab, in the Relationships group:

 Show Table  Opens the Show Table dialog box so that you can select tables and queries for
viewing in the Relationships window.

 Hide Table  Hides the selected table in the Relationships window.

Direct Relationships  Displays all relationships and related tables for the selected table in the
Relationships window, if they are not already displayed.

11
 All Relationships  Displays all of the relationships and related tables in your database in the
Relationships window. Note that hidden tables (tables for which the Hidden check box in the table's
Properties dialog box is selected) and their relationships will not be shown unless Show Hidden

Create a table relationship

You can create a table relationship by using the Relationships window, or by dragging a field onto a datasheet
from the Field List pane. When you create a relationship between tables, the common fields are not required to
have the same names, although it is often the case that they do. Rather, those fields must have the same data
type. If the primary key field is an AutoNumber field, however, the foreign key field can be a Number field if the
FieldSize property of both fields is the same. For example, you can match an AutoNumber field and a Number
field if the FieldSize property of both fields is Long Integer. When both common fields are Number fields, they
must have the same FieldSize property setting.

Create a table relationship by using the Relationships window

1. Click the Microsoft Office Button , and then click Open.

2. In the Open dialog box, select and open the database.

3. On the Database Tools tab, in the Show/Hide group, click Relationships.

4. If you have not yet defined any relationships, the Show Table dialog box automatically appears. If it
does not appear, on the Design tab, in the Relationships group, click Show Table.

The Show Table dialog box displays all of the tables and queries in the database. To see only tables,
click Tables. To see only queries, click Queries. To see both tables and queries, click Both.

5. Select one or more tables or queries and then click Add. When you have finished adding tables
and queries to the Relationships window, click Close.

6. Drag a field (typically the primary key) from one table to the common field (the foreign key) in the
other table. To drag multiple fields, press the CTRL key, click each field, and then drag them.

The Edit Relationships dialog box appears.

7. Verify that the field names shown are the common fields for the relationship. If a field name is
incorrect, click the field name and select a new field from the list.

To enforce referential integrity for this relationship, select the Enforce Referential Integrity check box.
For more information about referential integrity, see the Understanding Referential Integrity and the
Enforce Referential Integrity sections.

8. Click Create.

The relationship line is drawn between the two tables. If you selected the Enforce Referential Integrity
check box, the line appears thicker at each end. In addition, again only if you selected the Enforce
Referential Integrity check box, the number 1 appears over the thick portion of the line on one side of
the relationship, and the infinity symbol (∞) appears over the thick portion of the line on the other side.

12
Delete a table relationship
To remove a table relationship, you must delete the relationship line in the Relationships window. Carefully
position the cursor so that it points at the relationship line, and then click the line. The relationship line appears
thicker when it is selected. With the relationship line selected, press DELETE. Note that when you remove a
relationship, you also remove referential integrity support for that relationship, if it is enabled. As a result, Access
will no longer automatically prevent the creation of orphan records on the "many" side of a relationship.

1. Click the Microsoft Office Button , and then click Open.

2. In the Open dialog box, select and open the database.

3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships window appears.

If you have not yet defined any relationships and this is the first time you are opening the Relationships
window, the Show Table dialog box appears. If the dialog box appears, click Close.

4. On the Design tab, in the Relationships group, click All Relationships.

All tables that have relationships are displayed, showing relationship lines.

5. Click the relationship line for the relationship that you want to delete. The relationship line appears
thicker when it is selected.

6. Press the DELETE key.

–or–

Right-click and then click Delete.

7. Access might display the message Are you sure you want to permanently delete the selected
relationship from your database?. If this confirmation message appears, click Yes.

Change a table relationship

You change a table relationship by selecting it in the Relationships window and then editing it. Carefully position
the cursor so that it points at the relationship line, and then click the line to select it. The relationship line appears
thicker when it is selected. With the relationship line selected, double-click it or click Edit Relationships in the
Tools group on the Design tab. The Edit Relationships dialog box appears

Make your changes in the Edit Relationships dialog box

1. Click the Microsoft Office Button , and then click Open.

13
2. In the Open dialog box, select and open the database.

3. On the Database Tools tab, in the Show/Hide group, click Relationships.

The Relationships window appears.

If you have not yet defined any relationships and this is the first time you are opening the Relationships
window, the Show Table dialog box appears. If the dialog box appears, click Close.

4. On the Design tab, in the Relationships group, click All Relationships.

All tables that have relationships are displayed, showing relationship lines. Note that hidden tables
(tables for which the Hidden check box in the table's Properties dialog box is selected) and their
relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options
dialog box.

For more information about the Show Hidden Objects option, see the article Guide to the Navigation
Pane.

5. Click the relationship line for the relationship that you want to change. The relationship line appears
thicker when it is selected.

6. Double-click the relationship line.

–or–

On the Design tab, in the Tools group, click Edit Relationships.

The Edit Relationships dialog box appears.

7. Make your changes, and then click OK.

The Edit Relationships dialog box allows you to change a table relationship. Specifically, you can
change the tables or queries on either side of the relationship, or the fields on either side. You can also
set the join type, or enforce referential integrity and choose a cascade option. For more information
about the join type and how to set it, see the section Set the join type. For more information about how
to enforce referential integrity and choose a cascade option, see the s

QUERIES
A query is a set of instructions that you can use for working with data

Introduction
A select query is a type of database object that shows information in . A query can get its data from one or more
tables, from existing queries, or from a combination of the two. The tables or queries from which a query gets its
data are referred to as its recordsource.

Whether you create simple select queries by using a wizard or by working in Design view, the steps are
essentially the same. You choose the recordsource that you want to use and the fields that you want to include in
the query — and, optionally, you specify criteria to refine the results.
14
After you have created a select query, you run it to see the results. Running a select query is simple — you just
open it in Datasheet view. You can then reuse it whenever you need, for example, as a recordsource for a form,
report, or another query.

 NOTE    For more information about using a query as a recordsource for a form or report, see the article Use a
query as a recordsource for a form or report.

There are several types of query, each serving a different purpose. For example, a select query displays data. An
action query changes the data in its datasource, or creates a new table. A parameter query prompts you to
supply criteria when you run it. This topic only covers select queries.

SELECT QUERY

A select query is used to create subsets of data that you can use to answer specific questions. It can also be
used to supply data to other database objects. Once you create a select query, you can use it whenever you
need.

Create a select query

1. Open the database that contains the records you want to update.

2. On the Create tab, in the Other group, click Query Design.

The query designer opens, and the Show Table dialog box opens.

3. Select the table or tables that contain the records you want to update, click Add, and then click
Close.

The table or tables appear as one or more windows in the query designer, and the windows list all the
fields in each table. This figure shows the query designer with a typical table.

4. Double-click the fields that you want to update. The selected fields appear in the Field row in the
query design grid.

You can add one table field per column in the query design grid.

To add all the fields in a table quickly, double-click the asterisk (*) at the top of the list of table fields.
This figure shows the query design grid with all fields added.

15
5. Optionally, you can enter one or more criteria in the Criteria row of the query design grid. The
following table shows some example criteria and explains the effect they have on the results of a query.

Add criteria to the query


To restrict the records that are returned in the query results, you can specify one or more criteria.

You can think of a query criterion as a condition that you specify for a field. The criterion specifies a condition,
based on field values, that expresses what you want to include in the query, such as "show only those records
where the value of City is London".

Open the query in Design view. You will add a criterion to the City field so that you see only those contacts who
are from London in the query results. You will also add criteria to the Address field and the Phone field, to further
refine your query results.

1. In the Criteria row of the City field, type london.

Now, add two more criteria to make the results even more meaningful. Suppose that you only want to
see the records in which both the address and the phone number are present.

2. In the Criteria row of the Address field, type Is Not Null AND <>"". Do the same in the Criteria
row of the Phone field.

 NOTE    The criterion, Is Not Null AND <>"", is true whenever there is any known, non-empty value for
the field for which it is a criterion. It is false whenever there is no known value (Null), or when the value
is known to be empty (""). You can use this expression to check a field for a known, non-empty value.

3. Switch to Datasheet view to see the results.

Review the SQL statement with criteria

What if you don't want the conditions to get combined by using the AND operator? In other words, how do you
specify two or more criteria but include the records that satisfy one or both of them?

Specify alternate criteria sets by using OR

Suppose you want to see all the records where City equals London and where at least one kind of contact
information — either the address or the phone number — is available. You want to combine the criteria by using
the OR operator, like this:

To specify alternate criteria, use both the Criteria and Or rows in the design grid. All records that meet the
criteria defined either in the Criteria row or in the Or row are included in the result.

Now you will modify the query by entering alternate criteria in the Criteria and Or rows.

1. Switch back to Design view.

2. Remove the Is Not Null AND <>"" string from the Criteria row of the Phone field.

3. In the Or row of the Phone field, type Is Not Null AND <>"".

4. In the Or row of the City field, type london.

16
5. Switch to Datasheet view to see the results. All records that include either an address, a phone
number, or both, and where City is London, are displayed in the query results.

Add calculations to the query


A well designed database does not store simple calculated values in tables. For example, a table might store a
person's date of birth but not their current age. If you know both today's date and the person's date of birth, you
can always calculate their current age, so there is no need to store that in the table. Instead, you create a query
that calculates and displays the pertinent value. The calculations are made every time you run the query, so if the
underlying data changes, so do your calculated results.

In this exercise, you will modify the London Contacts query so that it displays each contact's date of birth and
current age.

1. Open the query in Design view.

2. From the Customers table window, drag the BirthDate field to the first blank column in the design
grid. You can also double-click the field name to automatically add it in the first blank column.

3. In the next column, in the Field row, type the expression that will calculate the age for each record.
Type Age: DateDiff ("yyyy", [BirthDate], Date()).

Age is the name you are using for the calculated field. If you do not supply a name, Access will use a
generic name for the field, for example, EXPR1. The string following the colon (:) is the expression that
supplies the values for each record. The DateDiff function calculates the difference between any two
dates, and returns that difference in the specified format. The format, yyyy, returns the difference in
years, and the [BirthDate] and Date() elements of the expression supply the two date values. Date is a
function that returns the current date, and [BirthDate] refers to the BirthDate field in the underlying table.

 NOTE    The calculation used for Age in this example is an approximation that may be slightly
inaccurate, depending on the current month.

Switch to Datasheet view. You see two additional fields, BirthDate and Age, in the result.

For more information about how to write expressions that calculate values in a query, see the article Create an
expression.

Run a query

You run a query to perform these instructions. In addition to returning results — which can be sorted, grouped,
or filtered — a query can also create, copy, delete, or change data.

Run query
There are four types of action queries: , , , and . Except for make-table queries (which create new tables), action
queries make changes to the data in tables they are based on. These changes cannot be easily undone, for
example, by pressing CTRL+Z. If you make changes using an action query that you later decide you didn't want
to make, usually you will have to restore the data from a backup copy. For this reason, you should always make
sure you have a fresh backup of the underlying data before running an action query.

You can mitigate the risk of running an action query by first previewing the data that will be acted upon. There are
two ways to do this:

View the action query in Datasheet view before you run it. To do this, open the query in Design
view, click View on the Access , and then click Datasheet View on the shortcut menu. To switch back
to Design view, click View again, and then click Design View on the shortcut menu.

Change the query to a select query, and then run it.

 NOTE    Make sure to note what type of action query (append, update, make-table, or delete) you are
starting with, so you can change the query back to that type after you preview the data with this method.

Run an action query as a select query

17
1. Open the action query in Design view.

2. On the Design tab, in the Query Type group, click Select.

3. On the Design tab, in the Results group, click Run.

Run the query

When you are ready to run an action query, double-click it in the Navigation Pane, or click it and then press
ENTER.

Run a parameter query


A prompts you for a value when you run it. When you supply the value, the parameter query applies it as a field
criterion. Which field it applies the criterion to is specified in the query design. If you do not supply a value when
prompted, the parameter query interprets your input as an empty string.

A parameter query is always also another type of query. Most parameter queries are select queries or crosstab
queries, but append, make-table, and update queries can also be parameter queries.

You run a parameter query according to its other query type, but, in general, use the following procedure.

Run the query

1. Locate the query in the Navigation Pane.

2. Do one of the following:

 Double-click the query you want to run.

 Click the query you want to run, then press ENTER

ACTION QUERIES
AN UPDATE QUERY

Understand update queries

You use update queries to add, change, or delete the data in one or more existing records. You can think of
update queries as a powerful form of the Find and Replace dialog box. You enter a select criterion (the rough
equivalent of a search string) and an update criterion (the rough equivalent of a replacement string). Unlike the
Find and Replace dialog box, update queries can accept multiple criteria, allow you to update a large number of
records in one pass, and allow you to change records in more than one table at one time.

Remember these rules as you proceed:

You cannot use an update query to add new records to a table, but you can change existing null
values to non-null values. To add new records to one or more tables, you use an append query.

For more information about append queries, see the article Create an append query.

You cannot use an update query to delete entire records (rows) from a table, but you can change
existing non-null values to null. To delete entire records (a process that also deletes the primary key
value), you must use a delete query.

For more information about delete queries, see the article Use a delete query to delete one or more
records from a database.

You can use an update query to change all the data in a set of records.

Create and run an update query

18
The safest way to use an update query is to first create a select query that tests your selection criteria. For
example, suppose that you want to update a series of Yes/No fields from No to Yes for a given customer. To do
so, you can add criteria to your select query until it returns all of the records that contain No in the records for that
customer. When you are sure that the query returns the correct records, you then convert it to an update query,
enter your update criteria, and then run the query to change the selected values. The steps in this section explain
how to create a select query and then convert it to an update query.

Create a select query

1. Open the database that contains the records you want to update.

2. On the Create tab, in the Other group, click Query Design.

The query designer opens, and the Show Table dialog box opens.

3. Select the table or tables that contain the records you want to update, click Add, and then click
Close.

The table or tables appear as one or more windows in the query designer, and the windows list all the
fields in each table. This figure shows the query designer with a typical table.

4. Double-click the fields that you want to update. The selected fields appear in the Field row in the
query design grid.

To add all the fields in a table quickly, double-click the asterisk (*) at the top of the list of table fields.
This figure shows the query design grid with all fields added.

5. Optionally, you can enter one or more criteria in the Criteria row of the query design grid. The
following table shows some example criteria and explains the effect they have on the results of a query.

The following grid shows most used wild cards.

Criteria Effect

19
>234 Returns all numbers greater than 234. To find all numbers less than 234, use < 234.

>="Cajhen" Returns all records from Cajhen through the end of the alphabet.

Between #2/2/2007# Returns dates from 2-Feb-07 through 1-Dec-07 (ANSI-89). If your database uses the ANSI-92 wildcard characters, use
And #12/1/2007# single quotation marks (') instead of pound signs (#). Example: Between '2/2/2007' And '12/1/2007' .

Not "Germany" Finds all records where the exact contents of the field are not exactly equal to "Germany." The criterion will return records
that contain characters in addition to "Germany," such as "Germany (euro)" or "Europe (Germany)".

Not "T*" Finds all records except those beginning with T. If your database uses the ANSI-92 wildcard character set, use the percent
sign (%) instead of the asterisk (*).

Not "*t" Finds all records that do not end with t. If your database uses the ANSI-92 wildcard character set, use the percent sign
(%) instead of the asterisk (*).

In(Canada,UK) In a list, finds all records containing Canada or UK.

Like "[A-D]*" In a text field, finds all records that start with the letters A through D. If your database uses the ANSI-92 wildcard
character set, use the percent sign (%) instead of the asterisk (*).

Like "*ar*" Finds all records that include the letter sequence "ar". If your database uses the ANSI-92 wildcard character set, use the
percent sign (%) instead of the asterisk (*).

Like "Maison Dewe?" Finds all records that begin with "Maison" and contain a 5-letter second string in which the first 4 letters are "Dewe" and
the last letter is unknown. If your database uses the ANSI-92 wildcard character set, use the underscore (_) instead of the
question mark (?).

#2/2/2007# Finds all records for February 2, 2007. If your database uses the ANSI-92 wildcard character set, surround the date with
single quotation marks (') instead of pound signs (#); for example, ('2/2/2007').

< Date() - 30 Uses the Date function to return all dates more than 30 days old.

Date() Uses the Date function to return all records containing today's date.

Between Date() And Uses the Date and DateAdd functions to return all records between today's date and three months from today's date.
DateAdd("M", 3,
Date())

Is Null Returns all records that contain a null (blank or undefined) value.

Is Not Null Returns all records that contain a value.

"" Returns all records that contain a zero-length string. You use zero-length strings when you need to add a value to a
required field, but you don't yet know what that value is. For example, a field might require a fax number, but some of
your customers might not have fax machines. In that case, you enter a pair of double quotation marks with no space
between them ("") instead of a number.

6. On the Design tab, in the Results group, click Run.

Verify that the query returns the records that you want to update. As needed, you can select fields you

don't want included in the query design and press DELETE to remove them. In addition, you can drag

additional fields to the query design grid.

. Update data from one table to another

A large number of database users find that they have to update the data in one table with data from another —
and many of those users often find the task hard to complete. When you need to update data from one table to
another, keep this rule in mind: the data types for the source and destination fields must either match or be
compatible.

Also, when you update data from one table to another and use compatible data types instead of matching data
types, Access converts the data types of those fields in the destination table. As a result, some of the data in the
destination fields might be truncated (deleted). The section Restrictions on data type conversions lists the ways
in which you can and cannot convert data types. The table also explains when converting a data type can change
or eliminate some or all of the data in a field and what data might be eliminated.

20
The process of updating data from one table to another follows these broad steps:

Create an update query and add both the source and destination tables to the query.

Join those tables on the fields that contain the related information.

Add the names of your destination fields to the Field row of the query design grid.

Add the names of your source fields to the Update To row of the query design grid by using the
following syntax: [source_table].[source_field].

Create and run the update query

1. On the Create tab, in the Other group, click Query Design.

2. In the Show Table dialog box, double click your source and destination tables to add them to the
query. Each table appears in a window in the query designer. When you have finished adding tables,
click Close to close the Show Table dialog box.

3. Join the tables on the fields that contain the related information. To do so, drag the related field
from one table and drop it on the equivalent field in the other table.

For example, if you use the sample tables shown earlier, you drag the Client ID field to the Customer ID
field. When you do so, Access creates a relationship between those fields in the two tables and uses
that relationship to join any related records.

4. On the Design tab, in the Query Type group, click Update.

5. In the destination table, double-click the fields that you want to update. Each field appears in the
Field row in the query design grid.

If you use the sample tables, you add all fields except the Customer ID field. Notice that the name of
the destination table appears in the Table row of the design grid.

6. In the Update To row of the query, in each of the columns that contains a destination field, add the
name of the source table and the field in the source table that corresponds to the field in the destination
table, and be sure to use this syntax: [Table].[Field], where you surround table and field names with
square brackets, and you separate table and field names with a period.

This figure shows part of the design grid, using the sample tables. Note the syntax for the table and
field names in the Update To row.

As you proceed, remember that you must spell the table and field names in the Update To row

correctly, and you must match any punctuation in the original table and field names. However, you do
not need to match capitalization.

7. On the Design tab, in the Results group, click Run.

8. When asked to confirm the update, click Yes.

APPEND QUERIES

21
An append query adds a set of records (rows) from one or more source tables (or queries) to one or more
destination tables. Typically, the source and destination tables reside in the same database, but they don't have
to. For example, suppose that you acquire some new customers and a database that contains a table of
information about those customers. To avoid entering that new data manually, you can append it to the
appropriate table in your database. You can also use append queries to:

Append fields that are based on criteria. For example, you might want to append only the names
and addresses of customers who have outstanding orders.

Append records when some of the fields in one table don't exist in the other table. For example,
suppose that your Customers table has 11 fields, and the fields in the Clients table in another database
match 9 of your 11 fields. You can use an append query to add only the data in the matching fields and
ignore the others.

Remember that you cannot use append queries to change the data in individual fields in existing records. To do
that type of task, you use an update query — you can only use append queries to add rows of data.

For more information about update queries, see the article Create an update query. For general information
about other ways to add records to a database or change existing data, see the article Add one or more records
to a database.

Create and run an append query

The process of creating an append query follows these basic steps:

Create a select query.

Convert the select query to an append query.

Choose the destination fields for each column in the append query.

Run the query to append the records.

Convert the select query to an append query


1. Right-click the document tab for the open query and click Design View on the shortcut menu.

-or-

In the Navigation Pane, right-click the query and then click Design View on the shortcut menu.

2. On the Design tab, in the Query Type group, click Append.

The Append dialog box appears.

3. At this point, you can choose whether to append records from one table to an existing table in the
same database, or to an existing table in a different database.

1. Follow the steps in this section to create a select query. Modify the select query as
needed until it returns the records that you want to place in the new table.

2. Switch to query Design view. Right-click the document tab for the query, and then click
Design View.

-or-

Right-click the query in the Navigation Pane, and then click Design View.

3. On the Design tab, in the Query Type group, click Make Table.

The Make Table dialog box appears.

4. In the Table Name combo box, enter a name for the new table.

22
5. Do one of the following:

 Place the new table in the open database.

 Leave Current Database selected and click OK

 Place the new table in another database.

 Click Another Database.

 Enter the file path and name of the other database, or click
Browse to locate the database, and then click OK after you locate the database.

 In the Table Name combo box, enter a name for the new table.

 Click OK.

Now that you have converted the query, you need to decide whether you want to append the records to a table in
the same database or to a table in a different database. Depending on your choice, use the steps in one of the
two following procedures:

Append records to a table in the same database


1. In the Append dialog box, click Current Database (if it isn't already selected), and
then select the destination table from the Table Name combo box.

2. Click OK.

What you see depends on how you created your select query. For example, if you added all the
fields from your source table or query, Access now adds all the fields in the destination table to
the Append to row in the design grid.

-or-

If you added individual fields to the query, and the field names in the source and destination
tables match, Access automatically adds the names of the destination fields to the Append to
row in the query.

-or-

If you added individual fields, and any of the names in the source and destination tables don't
match, Access leaves those fields blank. You can click a cell in the Append to row and select a
destination field.

This figure illustrates how you click a cell in the Append to row and select a destination field.

3. To preview your changes, switch to Datasheet view. To do so, right-click the document
tab for the query, and then click Datasheet View.

-or-

In the Navigation Pane, right-click the query and then click Datasheet View.

23
4. Return to Design view, and then click Run to append the records.

Reminder  You cannot undo the results of an append query, so make very sure that you want to
append the records.

Append records to a table in another database


In the Append dialog box, click Another Database.

In the File Name box, enter the location and name of the destination database.

In the Table Name combo box, enter the name of the destination table, and then click
OK.

–or–

Click Browse and use the subsequent Append dialog box to locate the destination database.
Click OK after you locate and select the destination database. This closes the subsequent
Append dialog box. In the first Append dialog box, in the Table Name combo box, enter the
name of the destination table, and then click OK.

What you see depends on how you created your select query. For example, if you added all the
fields from your source table or query, Access now adds all the fields in the destination table to
the Append to row in the design grid.

-or-

If you added individual fields to the query, and the field names in the source and destination
tables match, Access automatically adds the names of the destination fields to the Append to
row in the query.

-or-

If you added individual fields, and any of the names in the source and destination tables don't
match, Access leaves those fields blank. You can click a cell in the Append to row and select a
destination field.

This figure illustrates how you click a cell in the Append To row and select a destination field.

MAKE TABLE QUERIES

A make table query retrieves data from one or more tables, and then loads the result set into a new table. That
new table can reside in the database that you have open, or you can create it in another database.

Typically, you create make table queries when you need to copy or archive data. For example, suppose you have
a table (or tables) of past sales data, and you use that data in reports. The sales figures cannot change because
the transactions are at least one day old, and constantly running a query to retrieve the data can take time —
especially if you run a complex query against a large data store. Loading the data into a separate table and using
that table as a data source can reduce workload and provide a convenient data archive. As you proceed,

remember that the data in your new table is strictly a snapshot; it has no relationship or connection to its source
table or tables.

Create a make table query

You create a make table query by first creating a select query, and then converting it to a make table query. Your
select query can use calculated fields and expressions to help return the data that you need. The following steps
explain how to create and convert the query. If you already have a select query that fits your needs, you can skip
ahead to the steps for converting the select query and running the make table query.

Enable the database

 NOTE    Follow these steps only when your database does not reside in a trusted location or is not signed.
Access displays the Message Bar whenever you open an untrusted or unsigned database.

24
1. On the Message Bar, click Options.

2. In the Microsoft Office Security Options dialog box, click Enable this content, and then click
OK.

If you don't see the Message Bar

On the Database Tools tab, in the Show/Hide group, click Message Bar.

Convert the select query

1. Open your select query in Design view, or switch to Design view. Access provides several ways to
do this:

 If you have the query open in a datasheet, right-click the document tab for your query
and click Design View.

 If the query is closed, in the Navigation Pane, right-click the query and click Design
View on the shortcut menu.

2. On the Design tab, in the Query Type group, click Make Table.

The Make Table dialog box appears.

3. In the Table Name box, enter a name for the new table.

-or-

Click the down-arrow and select an existing table name.

4. Do one of the following:

 Place the new table in the current database  

1. If it isn't already selected, click Current Database, and then click OK.

2. Click Run , and then click Yes to confirm the operation.

 Place the new table in another database  

1. Click Another Database.

2. In the File Name box, enter the location and file name of the other
database.

-or-

Click Browse, use the new Make Table dialog box to locate the other database, and click
OK.

3. Click OK to close the first Make Table dialog box.

4. Click Run , and then click Yes to confirm the operation.

FORMS
Create a form

A form is a database object that you can use to enter, edit, or display data from a table or a query. You can use
forms to control access to data, such as which fields or rows of data are displayed. For example, certain users
might need to see only several fields in a table with many fields. Providing those users with a form that contains
just those fields makes it easier for them to use the database. You can also add buttons and other functionality to
a form to automate frequently performed actions.

25
Think of forms as windows through which people see and reach your database. An effective form speeds the use
of your database, because people don't have to search for what they need. A visually attractive form makes
working with the database more pleasant and more efficient, and it can also help prevent incorrect data from
being entered

Create a form by using the Form tool

You can use the Form tool to create a form with a single mouse-click. When you use this tool, all the fields from
the underlying data source are placed on the form. You can begin using the new form immediately, or you can
modify it in Layout view or Design view to better suit your needs.

Use the Form tool to create a new form

1. In the Navigation Pane, click the table or query that contains the data you want to see on your
form.

2. On the Create tab, in the Forms group, click Form.

Access creates the form and displays it in Layout view. In Layout view, you can make design changes to the form
while it is displaying data. For example, you can adjust the size of the text boxes to fit the data, if necessary. For
more information about form views, see the Understand Layout view and Design view section.

If Access finds a single table that has a one-to-many relationship with the table or query that you used to create
the form, Access adds a datasheet to the form that is based on the related table or query. For example, if you
create a simple form that is based on the Employees table, and there is a one-to-many relationship defined
between the Employees table and Orders table, the datasheet displays all the records in the Orders table that
pertain to the current Employee record. You can delete the datasheet from the form if you decide you do not
need it. If there is more than one table with a one-to-many relationship to the table that you used to create the
form, Access does not add any datasheets to the form

Create a split form by using the Split Form tool

The two views are connected to the same data source and are synchronized with each other at all times.
Selecting a field in one part of the form selects the same field in the other part of the form. You can add, edit, or
delete data from either part (provided that the record source is updateable, and you have not configured the form
to prevent these actions).

To create a split form by using the Split Form tool:

1. In the Navigation Pane, click the table or query that contains the data that you want on your form.
Or open the table or query in Datasheet view.

2. On the Create tab, in the Forms group, click Split Form.

Create a form that displays multiple records by using the Multiple Items tool

When you create a form by using the Simple Form tool, the form that Access creates displays a single record at a
time. If you want a form that displays multiple records but is more customizable than a datasheet, you can use
the Multiple Items tool.

1. In the Navigation Pane, click the table or query that contains the data you want to see on your
form.

2. On the Create tab, in the Forms group, click Multiple Items.

Access creates the form and displays it in Layout view. In Layout view, you can make design changes to the form
while it is displaying data. For example, you can adjust the size of the text boxes to fit the data. For more
information about form views, see the Understand Layout view and Design view section.

26
When you use the Multiple Items tool, the form that Access creates resembles a datasheet. The data is arranged
in rows and columns, and you see more than one record at a time.

Create a form by using the Form Wizard

To be more selective about what fields appear on your form, you can use the Form Wizard instead of the various
form-building tools previously mentioned. You can also define how the data is grouped and sorted, and you can
use fields from more than one table or query, provided that you specified the relationships between the tables
and queries beforehand. For more information about creating relationships, see the links in the See Also section
of this article.

1. On the Create tab, in the Forms group, click More Forms, and then click Form Wizard.

2. Follow the directions on the pages of the Form Wizard.

 NOTE    If you want to include fields from multiple tables and queries on your form, do not click Next or
Finish after you select the fields from the first table or query on the first page of the Form Wizard.
Instead, repeat the steps to select a table or query, and click any additional fields that you want to
include on the form. Then click Next or Finish to continue.

3. On the last page of the wizard, click Finish.

Create a form by using the Blank Form tool

If the wizard or the form-building tools don't fit your needs, you can use the Blank Form tool to build a form. This
can be a very quick way to build a form, especially if you plan to put only a few fields on your form.

1. On the Create tab, in the Forms group, click Blank Form.

Access opens a blank form in Layout view, and displays the Field List pane.

27
Understand controls

Controls are objects that display data, perform actions, and let you view and work with information that enhances
the user interface, such as labels and images. The most commonly used control is the text box, but other controls
include labels, check boxes, and subform/subreport controls.

Controls can be bound, unbound, and calculated:

Bound control  A control whose source of data is a field in a table or query is called a bound
control. You use bound controls to display values that come from fields in your database. The values
can be text, dates, numbers, Yes/No values, pictures, or graphs. For example, a text box on a form that
displays an employee's last name might get this information from the Last Name field in the Employees
table.

Unbound control  A control that doesn't have a source of data (such as a field or expression) is
called an unbound control. You use unbound controls to display information, lines, rectangles, and
pictures. For example, a label that displays the title of a form is an unbound control.

Calculated control  A control whose source of data is an expression, rather than a field, is called a
calculated control. You specify the value that you want to use as the source of data in the control by
defining an expression. An expression can be a combination of operators (such as = and + ), control
names, field names, functions that return a single value, and constant values. For example, the
following expression calculates the price of an item with a 25 percent discount by multiplying the value
in the Unit Price field by a constant value (0.75).

=[Unit Price] * 0.75

An expression can use data from a field in the form's underlying table or query, or data from another
control on the form.

Create a new control layout

Access automatically creates stacked control layouts in either of the following circumstances:

You create a new form by clicking Form in the Forms group on the Create tab.

You create a new form by clicking Blank Form in the Forms group on the Create tab, and then
dragging a field from the Field List pane to the form.

On an existing form, you can create a new control layout by doing the following:

1. Select a control that you want to add to the layout.

2. If you want to add other controls to the same layout, hold down the SHIFT key and also select
those controls.

3. Do one of the following:

 On the Arrange tab, in the Control Layout group, click Tabular or Stacked .

 Right-click the selected control or controls, point to Layout, and then click Tabular
or Stacked .

Remove controls from a control layout

Select the control you want to remove from the layout. To select multiple controls, hold down the
SHIFT key and then click the controls you want to remove. To select all of the controls in the layout,
click the layout selector box at the top left corner of the layout.

Do one of the following:

 On the Arrange tab, in the Control Layout group, click Remove .

28
 Right-click one of the selected controls, point to Layout, and then click Remove .

Access removes the selected controls from the layout.

Understand Layout view and Design view

Layout view  Layout view is the most intuitive view to use for form modification, and it can be used for nearly all
the changes you would want to make to a form in Office Access 2007. In Layout view, the form is actually
running, so you can see your data much as it will appear in Form view. However, you can also make changes to
the form design in this view. Because you can see the data while you are modifying the form, this is a very useful
view for setting the size of controls or performing almost any other task that affects the appearance and usability
of the form.

Certain tasks cannot be performed in Layout view and require switching to Design view. In certain situations,
Access displays a message telling you that you must switch to Design view to make a particular change.

Design view  Design view gives you a more detailed view of the structure of your form. You can see the Header,
Detail, and Footer sections for the form. The form is not actually running when it is shown in Design view, so you
cannot see the underlying data while you are making design changes; however, there are certain tasks you can
perform more easily in Design view than in Layout view. You can

REPORT
A report consists of information that is pulled from tables or queries, as well as information that is stored with the
report design, such as labels, headings, and graphics. The tables or queries that provide the underlying data are
also known as the report's record source. If the fields that you want to include all exist in a single table, use that
table as the record source. If the fields are contained in more than one table, you need to use one or more
queries as the record source. Those queries may already exist in your database, or you may need to create new
queries specifically to fit the needs of your report. You can find links to more information about queries in the See
Also section.

Create a report by using the Report tool


The Report tool provides the fastest way for you to create a report, because it generates a report immediately
without prompting you for information. The report displays all the fields from the underlying table or query. The
Report tool may not create the final, polished product that you ultimately want, but it is quite useful as a means to
quickly look at the underlying data. You can then save the report and modify it in Layout view or Design view so
that it better serves your purposes.

1. In the Navigation Pane, click the table or query on which you want to base the report.

2. On the Create tab, in the Reports group, click Report.

Access builds the report and displays it in Layout view.

3. For more about viewing and printing your report, see the section View, print, or send your report as
an e-mail message.

After viewing the report, you can save it and then close both the report and the underlying table or query that you
used as a record source. The next time that you open the report, Access will display the most recent data from
your record source.

Create a report by using the Report Wizard


You can use the Report Wizard to be more selective about what fields appear on your report. You can also
specify how the data is grouped and sorted, and you can use fields from more than one table or query, provided
you have specified the relationships between the tables and queries beforehand. Find links to more information
about creating relationships in the See Also section.

1. On the Create tab, in the Reports group, click Report Wizard.

2. Follow the directions on the Report Wizard pages. On the last page, click Finish.

29
When you preview the report, you see the report as it will appear in print. You can also increase the
magnification to zoom in on details. For more about viewing and printing your report, see the section
View, print, or send your report as an e-mail message.

 NOTE    If you want to include fields from multiple tables and queries in your report, do not click Next or Finish
after you select the fields from the first table or query on the first page of the Report Wizard. Instead, repeat the
steps to select a table or query, and click any additional fields that you want to include in the report. Then, click
Next or Finish to continue.

Create labels by using the Label Wizard


Use the Label Wizard to easily create labels for a wide variety of standard label sizes.

1. In the Navigation Pane, open the table or query that will be the record source for your labels by
double-clicking it.

2. On the Create tab, in the Reports group, click Labels.

3. Follow the directions on the pages of the Label Wizard. On the last page, click Finish.

Access displays your labels in Print Preview so that you can see them as they will appear when they are printed.
You can use the slider control on the Access status bar to zoom in on details. For more information about viewing
and printing your report, see the section View, print, or send your report as an e-mail message.

 NOTE    Print Preview is the only view you can use to see multiple columns — the other views show the data in a
single column.

Create a report by using the Blank Report tool


If you aren't interested in using the Report tool or the Report Wizard, you can use the Blank Report tool to build a
report from scratch. This can be a very quick way to build a report, especially if you plan to put only a few fields
on your report. The following procedure explains how to use the Blank Report tool:

1. On the Create tab, in the Reports group, click Blank Report.

A blank report is displayed in Layout view, and the pane is displayed on the right side of the Access
window.

2. In the Field List pane, click the plus sign next to the table or tables containing the fields that you
want to see on the report.

3. Drag each field onto the report one at a time, or hold down CTRL and select several fields, and
then drag them onto the report at the same time.

4. Use the tools in the Controls group on the Formatting tab to add a logo, title, page numbers, or
the date and time to the report.

Understand the report sections


In Access, the design of a report is divided into sections. You can view your report in Design view to see its
sections. To create useful reports, you need to understand how each section works. For example, the section in
which you choose to place a calculated control determines how Access calculates the results. The following list is
a summary of the section types and their uses:

Report Header   This section is printed just once, at the beginning of the report. Use the report
header for information that might normally appear on a cover page, such as a logo, a title, or a date.
When you place a calculated control that uses the Sum aggregate function in the report header, the
sum calculated is for the entire report. The report header is printed before the page header.

30
Page Header   This section is printed at the top of every page. For example, use a page header to
repeat the report title on every page.

Group Header   This section is printed at the beginning of each new group of records. Use the
group header to print the group name. For example, in a report that is grouped by product, use the
group header to print the product name. When you place a calculated control that uses the Sum
aggregate function in the group header, the sum is for the current group.

Detail   This section is printed once for every row in the record source. This is where you place the
controls that make up the main body of the report.

Group Footer   This section is printed at the end of each group of records. Use a group footer to
print summary information for a group.

Page Footer   This section is printed at the end of every page. Use a page footer to print page
numbers or per-page information.

Report Footer   This section is printed just once, at the end of the report. Use the report footer to
print report totals or other summary information for the entire report.

 NOTE    In Design view, the report footer appears below the page footer. However, when the report is
printed or previewed, the report footer appears above the page footer, just after the last group footer or
detail line on the final page.

Understand controls
Controls are objects that display data, perform actions, and let you view and work with information that enhances
the user interface, such as labels and images. Access supports three types of controls: bound, unbound, and
calculated:

 Bound control   A control whose source of data is a field in a table or query is a bound control.
You use bound controls to display values from fields in your database. The values can be text, dates,
numbers, Yes/No values, pictures, or graphs. A text box is the most common type of bound control. For
example, a text box on a form that displays an employee's last name might get this information from the
Last Name field in the Employees table.

 Unbound control   A control that doesn't have a source of data (a field or expression) is an
unbound control. You use unbound controls to display information, lines, rectangles, and pictures. For
example, a label that displays the title of a report is an unbound control.

 Calculated control   A control whose source of data is an expression rather than a field is a
calculated control. You specify the value that you want in the control by defining an expression as the
source of data for the control. An expression is a combination of operators (such as = and + ), control
names, field names, functions that return a single value, and constant values. For example, the
following expression calculates the price of an item with a 25 percent discount by multiplying the value
in the Unit Price field by a constant value (0.75).

= [Unit Price] * 0.75

An expression can use data from a field in the report's underlying table or query, or from a control in the
report.

When you create a report, it is probably most efficient to add and arrange all the bound controls first, especially if
they make up the majority of the controls on the report. You can then add the unbound and calculated controls
that complete the design by using the tools in the Controls group on the Design tab.

You bind a control to a field by identifying the field from which the control gets its data. You can create a control
that is bound to the selected field by dragging the field from the Field List pane to the report. The Field List
pane displays the fields of the report's underlying table or query. To display the Field List pane, on the Design
tab, in the Controls group, click Add Existing Field.

Alternatively, you can bind a field to a control by typing the field name in the control itself or in the box for the
ControlSource value in the control's property sheet. The property sheet defines the characteristics of the control,
such as its name, the source of its data, and its format.

Using the Field List pane is the best way to create a control for two reasons:
31
 A bound control has an attached label, and the label takes the name of the field (or the caption
defined for that field in the underlying table or query) as its caption by default, so you don't have to type
the caption yourself.

 A bound control inherits many of the same settings as the field in the underlying table or query
(such as for the Format, DecimalPlaces, and InputMask properties). Therefore, you can be sure that
these properties for the field remain the same whenever you create a control that is bound to that field.

If you already created an unbound control and want to bind it to a field, set the control's ControlSource property
to the name of the field. For details about the ControlSource property, search Help for "ControlSource."

View, print, or send your report as an e-mail message


After you save your report design, you can use it over and over again. The report's design stays the same, but
you get current data every time you view or print the report. If your reporting needs change, you can modify the
report design or create a new, similar report based on the original.

View your report


There are several ways to view your report. Which method you choose depends on what you want to do with the
report and its data:

If you want to make temporary changes to which data appears on the report before you print it, or if
you want to copy data from the report to the clipboard, use Report view.

If you want to be able to change the design of the report while looking at the data, use Layout view.

If you simply want to see what the report will look like when it is printed, use Print Preview.

 NOTE    If your report is formatted with multiple columns, you can only see the column layout in Print Preview.
Layout view and Report view display the report as a single column.

View your report in Report view

Report view is the default view that is used when you double-click a report in the Navigation Pane. If the report is
not open, double-click the report in the Navigation Pane to see it in Report view.

If the report is already open, right-click the report name in the Navigation Pane and then click Report View.

Work with your data in Report view

In Report view, you can select text and copy it to the clipboard. To select entire rows, click and drag in the margin
next to the rows that you want to select. You can then copy these rows to the clipboard by doing one of the
following:

 On the Home tab, in the Clipboard group, click Copy.

 Right-click the selected rows and then click Copy.

MACROS
You can create a macro (macro: An action or set of actions that you can use to automate tasks.) to perform a
specific series of actions (action: The basic building block of a macro; a self-contained instruction that can be
combined with other actions to automate tasks. This is sometimes called a command in other macro languages.),
and you can create a macro group (macro group: A collection of related macros that are stored together under a
single macro name. The collection is often referred to simply as a macro.) to perform related series of actions

Create a macro group

If you want to group several related macros in one macro object, you can create a macro group.

32
1. On the Create tab, in the Other group, click Macro. If this command is unavailable, click the arrow
beneath either the Module or the Class Module button, and then click Macro.

The Macro Builder is displayed.

2. On the Design tab, in the Show/Hide group, click Macro Names if it isn't already selected.

The Macro Name column is displayed in the Macro Builder

 NOTE    In macro groups, macro names are necessary to distinguish the individual macros from each other.
The macro name appears on the same line as the macro's first action. The macro name column is left blank
for any subsequent actions in the macro. The macro ends when the next macro name is encountered.

3. In the Macro Name column, type a name for the first macro in the macro group.

4. Add the actions that you want the first macro to carry out:

 In the Action column, click the arrow to display the action list.

 Click the action that you want to use.

 Under Action Arguments, specify arguments for the action, if any are required.

To see a short description of each argument, click in the argument box, and then read the
description on the right side of the argument.

 For an action argument whose setting is a database object name, you can
set the argument by dragging the object from the Navigation Pane to the action's Object
Name argument box.

 You can also create an action by dragging a database object from the
Navigation Pane to an empty row in the Macro Builder. If you drag a table, query, form,
report, or module to the Macro Builder, Access adds an action that opens the table, query,
form, or report. If you drag a macro to the Macro Builder, Access adds an action that runs
the macro.

 Optionally, type a comment for the action.

5. Move to the next empty row, and then type a name for the next macro in the Macro Name column.

6. Add the actions that you want the macro to carry out.

7. Repeat steps 5 and 6 for each macro in the macro group.

When you save the macro group, the name that you specify is the name of the group of macros. In the
preceding example, the name of the macro group is Macro3. This name is displayed under Macros in
the Navigation Pane. To refer to an individual macro in a macro group, use this syntax:

macrogroupname.macroname

For example, in the preceding illustration, Macro3.FoundMsg refers to the second macro in the macro
group.

8. If you run a macro group either by double-clicking it in the Navigation Pane or by clicking Run
in the Tools group on the Design tab, Access executes only the first macro in the group, stopping
when it reaches the second macro name.

Edit a macro
To insert an action row   Right-click the action row above which you want to insert the new action
row, and then click Insert Rows .

33
To delete an action row   Right-click the action row that you want to delete, and then click Delete
Rows .

To move an action row   Select the action row by clicking the row header to the left of the action,
and then drag it to a new position.

34

You might also like