You are on page 1of 59

Access 2010

Intermediate Skills

(C) 2013, BJC HealthCare (St Louis, Missouri). All Rights Reserved.

Revised June 5, 2013.

Microsoft Access 2010 Intermediate Skills

TABLE OF CONTENTS
OBJECTIVES ................................................................................................................................................................................. 3
UNDERSTANDING RELATIONSHIPS ...................................................................................................................................... 4
WHAT IS A RELATIONSHIP? ............................................................................................................................................................. 4
CREATING RELATIONSHIPS .............................................................................................................................................................. 7
EDITING TABLE RELATIONSHIPS USING JOIN PROPERTIES .................................................................................................................... 11
EDITING RELATIONSHIPS USING REFERENTIAL INTEGRITY .................................................................................................................... 14
CONTROLLING DATA ENTRY .............................................................................................................................................. 16
THE IMPORTANCE OF FIELD PROPERTIES .......................................................................................................................................... 16
SETTING UP DEFAULT VALUES AND REQUIRED FIELDS ........................................................................................................................ 19
DEVELOPING INPUT MASKS .......................................................................................................................................................... 22
DEFINING VALIDATION RULES........................................................................................................................................................ 27
CONTROLLING DATA ENTRY: LOOKUPS............................................................................................................................................ 32
PROPERTY SHEETS....................................................................................................................................................................... 38
USING EXPRESSIONS IN OBJECTS ....................................................................................................................................... 39
WHAT IS AN EXPRESSION? ............................................................................................................................................................ 39
USING EXPRESSIONS IN QUERIES.................................................................................................................................................... 40
USING EXPRESSIONS IN FORMS...................................................................................................................................................... 43
USING EXPRESSIONS IN REPORTS ................................................................................................................................................... 45
OTHER TYPES OF QUERIES ................................................................................................................................................. 49
QUERY OPTIONS......................................................................................................................................................................... 49
UPDATE QUERIES........................................................................................................................................................................ 49
MAKE TABLE QUERIES ................................................................................................................................................................. 51
APPEND QUERIES........................................................................................................................................................................ 53
DELETE QUERIES......................................................................................................................................................................... 55
PARAMETER QUERIES .................................................................................................................................................................. 57

Microsoft Access 2010 Intermediate Skills

OBJECTIVES
Upon completion of this course, participants will:

Describe relationships, join types, and referential integrity


Create relationships at the query and database levels
Change the output of a query by modifying the join type between the tables
Control data entry by enforcing referential integrity between tables
Describe the impact of the cascade options within referential integrity
Manage the properties of different field types
Set default values for fields
Mark fields as required for data entry
Create an standard and custom input mask to format the entered data
Create a validation rule for a field
Create a custom message for a validation rule
Create a data lookup based on data entered into a list
Create a data lookup that references another table
Create and use expressions in forms, queries, and reports
Create custom calculations
Combine data from separate fields
Create, modify, and run an Update query
Create and run a Make Table query
Create and run an Append query
Create and run a Delete query
Create and run a Parameter query

Microsoft Access 2010 Intermediate Skills

UNDERSTANDING RELATIONSHIPS
WHAT IS A RELATIONSHIP?
Newcomers to the database world have a hard time seeing the difference between an Excel spreadsheet and a database
table. They see the table grid structure and recognize that databases allow you better organize and query the data in new
ways, but many dont notice the power of the relationship function that gives this software its true power.
Relationships allow you describe the connections between different database tables. These connections allow you to
perform powerful cross-table queries called Joins.

RELATIONSHIP TYPES
There are three types of relationships in Access. These are named according to the number of table rows that may
be involved in the relationship.

ONE-TO-ONE RELATIONSHIP
These relationships occur when each entry in the first table has one, and only one counterpart or match in the
second table. A One-to-One relationship is created if both the related fields are primary keys or have unique
indexes. An index helps find and sort records faster. One-to-One relationships are rare because most of the time a
more efficient way is to just store both fields in the same table.
An example of a One-to-One relationship can be found in our class file between the Employee Data and Employee
Salary. One record that includes the employee basic name and address info in the Employee Data table matches
one record that contains the employees salary info in the Employee Salary table. The information is stored in
separate tables for confidentiality reasons.

Microsoft Access 2010 Intermediate Skills

The Primary key in the


first table matches up
with the primary key
in the second table.

ONE-TO-MANY RELATIONSHIP
These relationships are the most common type of database relationship. They occur when each record in the first
table corresponds to one or more records in the second table. A One-to-Many relationship is created if only one
of the related fields is a primary key or has a unique index.
An example of a One-to-Many relationship can be found with our class file between the Patient List and the Visits
table. A patient name record found in the Patient List table can be matches several times with visit information on
the Visits table. This means that the one patient can visit many times!

The Primary key in the


first table matches
more than one field in
the second table.

MANY-TO-MANY RELATIONSHIP
These relationships occur when each record in the first table matches one or more records in the second table and
each record in the second table also matches one or more records in the first table. Access cannot resolve manyto-many relationships. The application will produce an error immediately, as it cannot determine in which order to
match the records.
An example of a Many-to-Many relationship can be found with our class file between the Patient and the Doctor
List tables. A patient can see several doctors in the Doctor table and a doctor can see multiple patients in the
Patient table. This means there is no easy way to join the two tables because there are too many matches for
Access to try to resolve.

Doctors can see more


than one patient.

Patients can see more


than one doctor.

Microsoft Access 2010 Intermediate Skills

SOLVING A MANY TO MANY RELATIONSHIPS


Tables that need to be joined but cant because of a Many-to-Many relationship can exist in theory but cant exist
physically. There is no way to connect the fields properly. The solution to joining these tables so that data can be
retrieved is creating a Junction table. The Junction or Joining table can solve the problem by containing the
primary key from each of the tables and combine them to make up a unique primary key. This Junction table then
provides the bridge that provides a one-to-many relationship on each side.
One-to-Many

One-to-Many

Two primary keys combine to


make a unique record.
An example of a Junction table can be found with our class file between the Patient List, Doctor List and Visits
table. The combination of the Doctor ID, Patient ID, and Visit Date field provides a unique record. Now that we
joined these tables we can create queries that pull fields from all three tables. Dr last name, patient Last name,
gender, visit date and length.

Microsoft Access 2010 Intermediate Skills

CREATING RELATIONSHIPS
It is best to create the relationships before beginning to add data to your tables. Consider drawing your relationships on
paper before trying to create the links in your database. When you create a relationship between two tables, Access will
determine what type of relationship exists between the tables.

QUERY LEVEL VS DATABASE LEVEL RELATIONSHIPS


You can create a relationship between tables at the query level or at the database level. When you create a
relationship at the query level, the relationship exists for that query only. When you create a relationship at the
database level, the relationship extends into all database objects you create including forms, reports, queries, etc.
When you create a relationship, its not necessary for the linking fields to share the same names but they must be
the same data type. The exception to this is when the primary field has the AutoNumber data type. You can match
an AutoNumber field with a Number field as long as the field size property for both of the fields is the same.
Example of Relationship Created in Database Level

Example of Relationship Created in Query Level

Microsoft Access 2010 Intermediate Skills

Linking Two Tables at the Query Level


1.
2.

Open the Query in Design View.


Drag the linking (common) field from the first table to the same data type field on the second table.

Drag and drop one


field on top of the
other to join.

3.

Save the Query.

Instructions
1. Open the Access Intermediate Class database.
2. Double-click the Employee Payroll Query.
3. Click the Home tab.
4. Under the Views group, click Design View.
5.

Drag the ID field from the Employee Data table


onto the ID field in the Employee Salary table.

6.

Run the Query.

Comments
Note how many records return when the query is run.
Note that no link exists between the Employee Data
table and the Employee Salary table.
Your mouse will turn into a rectangle. Make sure your
mouse is positioned on the correct field before
releasing it.
Note the number of records is greatly reduced. Access
is no longer matching each record in the Employee
Data table with every record in the Employee Salary
table.

RELATIONSHIP TOOLS WITHIN THE RELATIONSHIP WINDOW


You can display a window that shows what relationships are set up within your database. This is found under the
Database Tools tab. The purpose of the Relationship Window is to show you how the fields between different
tables are linked. When you click on the Relationships button, a separate window opens. The Relationship Tools
tab also appears. This tab offers ways to edit the details of a selected relationship, adjust the layout, or print a
Relationship report. You can also add more tables to the window or adjust which relationships or tables are being
viewed.
Clears the
Relationship display
window.

Adds new tables


to the display.

Opens the Edit


Relationships window
to control all the
options with the
joined tables.

Closes the
Relationship
window.
Creates a printable
map of joined tables
within the database.

Controls which relationships


display in the window.

Microsoft Access 2010 Intermediate Skills

STEPS

Opening the Relationship Window

1. Click the Database Tools tab.


2. Under the Show/Hide group, select the Relationships button.

3. Click Close when finished.

NOTE!

Relationships are automatically saved as you click the Create button. If you are asked to save, you are saving
the layout (the position of the tables on the screen) and not the relationships you have created.

note

STEPS

Linking Two Tables at the Database Level (within the Relationships Window)

1.
2.
3.

Open the database.


Click the Database tools tab.
Under the Show/Hide group, click the Relationships button.

4.

Under the Relationships group, click Show Table.

5.
6.
7.

Select the table(s) you want to join and click Add. (Use the Ctrl key to select more than one table.)
Click Close.
Arrange the tables within the Relationships window.

Microsoft Access 2010 Intermediate Skills


8.
9.

Drag the linking (common) field from one table to the same data type field in the other table.
Verify the information in the Edit Relationships dialog box.

Notice that the field names


dont have to be the same
just the data type.
10. Click Create.

Instructions
1. Click the Database Tools tab.
2. Under the Show/Hide group, click Relationships.
3. Under the Relationships group, click Show Table.
4.
5.
6.
7.
8.

Select Employee Data table and click Add.


Select Employee Salary table and click Add.
Click Close.
Position your mouse on the border of the Employee Data
table.
Resize the table to view it in its entirety.

9. Repeat steps 8 & 9 to resize the Employee Salary table.


10. Drag the ID field from the Employee Data table onto the ID
field in the Employee Salary table.
11. Click Create.
12. Click Close.
13. Close the Relationships window.
14. Click Yes to save the layout of the tables.
15.
16.
17.
18.

Click the Create tab.


Under the Query group, click the Query Design button.
Add the Employee Data table and Employee Salary table.
Close without saving.

Comments
Opens the Relationship window.
Allows you to choose which tables you
want to display in the window.

Closes the Show Table window.

Resizing the table makes it easier to see all


the field names.
Make sure you have the correct fields.
Joins the tables and displays the join in the
Relationship window.
Closes the Relationship dialog box.
Saves the position and size of the displayed
tables.

Note that the link between the tables.

10

Microsoft Access 2010 Intermediate Skills

EDITING TABLE RELATIONSHIPS USING JOIN PROPERTIES


When two tables are joined in a relationship or query, the join tells Access how the data in the table is related and the type
of join will dictate which records the query performs an action on. It is important to understand the nature of join
properties and how join types greatly impact data output.

JOIN TYPES
There are three join types that Access supports. The primary table is determined by the way you create the links
(from left to right or from right to left).

EQUAL JOIN
An equal join, which is the default join type, will return only those records where there is a match
between both tables.
LEFT OUTER JOIN
A left outer join will return all records of the table designated to be the primary (or left) table, and
matching records, if any, from the linked table.
RIGHT OUTER JOIN
A right outer join will return all records of the table to be the primary (or right) table, and matching
records, if any, from the linked table.

Patients

Left Outer

Equal

Visits

Right Outer

JOIN PROPERTIES
You can control the output of your queries by changing the properties of the links between the tables. This is called
Join Properties. Most often, you will want to do this at the query level.
The default show only
matched fields.

You can right-click on the join line and choose Join Properties from the short-cut menu.

NOTE!
note

11

Microsoft Access 2010 Intermediate Skills

STEPS

Changing the Join Type in a Query

1. Open the query in Design View, if necessary.


Double-click on the join line you want to modify.

2. Select a Join Type: 1, 2, or 3.

3. Click OK.
4. Run the query.
Instructions
1. In the Navigation Pane, find the Tables category.
2. Open the Patient List table.
3. Close the table.
4. Open the Visits table.
5. Close the table.
6. In the Navigation Pane, find the Queries category.
7. Open the Patients and Visits query.
8. Switch to Design View.
9. Double-click on the join line between the Patient List
and Visits tables.
10. Select the Include All Records from Patient List and
only those records from Visits where the joined
fields are equal option.
11. Click OK.

12. Run the query.

Comments
There are 50 patient records.
There are 40 visit records.

How many records display?


The Join Properties dialog box will appear. Note
that the default option is to return only those
records where there is a match between the tables.

Note that the join line now shows which table is the
one and which table is the many in the
relationship.
Note the number of records has increased as all
patients are now listed.

13. Save and close the query.


14. Close the database.

12

Microsoft Access 2010 Intermediate Skills

STEPS
STEPS

Changing the Join Type in the Relationships Window

1. Click the Database Tools tab.


2. Under the Relationships group, click the Relationships command.
3. Double-click on the join line you want to modify.

4. Click the Join Type command button.

5. Select the desired join option.

6. Click OK.
7. Close the Relationships window.

When you make a change in the Relationships window, the new setting will be applied
to all subsequent queries created that use those tables.

NOTE!
note

13

Microsoft Access 2010 Intermediate Skills

EDITING RELATIONSHIPS USING REFERENTIAL INTEGRITY


Referential integrity is a system of rules that Microsoft Access uses to ensure that relationships between records in linked
tables are valid. Referential integrity makes sure that you don't accidentally add, delete, or change records that violate the
rules you set. For instance, you may set referential integrity on a relationship between tables such as Patients and Visits to
ensure that you do not record a visit for a patient that does not exist in the Patients table. Referential integrity is set at the
database level using the Relationships window.

STEPS

1.
2.
3.
4.

Enforcing Referential Integrity


Open the Relationships window.
Add the tables and create the appropriate links, if necessary.
Double-click on the join line for the tables for which you want to establish referential integrity.
Click the Enforce Referential Integrity check box.

5. Click the Cascade Update and Delete options, if required.


6. Click OK.
7. Close the Relationships window.
Instructions
1. Open the Employee Data table.
2. Close the table.
3. Open the Employee Salary table.
4. Add a new record with the following information:
ID:
999
DOH:
7/5/2012
Position
Lead Nurse
Rate:
30
Manager:
Collins
5. Click elsewhere in the table to save the record.
6. Delete the record.
7. Close the table.
8. Click the Database Tools tab.
9. Under the Show/Hide group, select the Relationships
button.
10. Double-click on the join line between the Employee Data
and Employee Salary table.

Comments
Notice how many employees there are.

Note that the customer 9999 does not exist in


the Customers table.

The record is allowed to be saved.

The Edit Relationships window will open.

14

Microsoft Access 2010 Intermediate Skills

Instructions
11. Click the Enforce Referential Integrity checkbox.
12. Click OK.
13. Close the Relationships window.
14. Reopen the Employee Salary table.
15. Add a record using the same information in step 4.
16. Click elsewhere in the table to attempt to save the
record.
17. Click OK to close the error message.

Comments

A message stating that the record cannot be


saved will appear.
The record cannot be saved as the customer
does not exist in the Customers table.

18. Press ESC to cancel the record.


19. Close the table.
20. Close the database.

CASCADE UPDATE/DELETE RELATED FIELDS


The Cascade Update option allows you to change a record in the primary table (the one side of the one-to-many)
and have Access automatically update all matching records in related tables. The Cascade Delete option allows
you to delete a record in the primary table and have Access delete all matching records in the related table. Use
caution when activating either option!

STEPS

Activating the Cascade Update and Cascade Delete Options


1. Open the Relationships window.
2. Add the tables and create the appropriate links, if necessary.
3. Double-click on the join line for the tables for which you want to initiate the Cascade Update or
Cascade Delete options.

4. Activate the Enforce Referential Integrity checkbox. The Cascade options will become available.
5. Select the desired option.

6. Click OK.
7. Close the Relationships window.

15

Microsoft Access 2010 Intermediate Skills

CONTROLLING DATA ENTRY


THE IMPORTANCE OF FIELD PROPERTIES
The fields in your database have settings that determine the type of data they can store, how the data is displayed, and
what you can do with the data. The fields data type controls what can be entered into the field. For instance, text data
cannot be entered into a field assigned the Number data type. The data type also determines the actions you can perform
on a field and how much space the data uses.
Each field also has properties that define its characteristics and behavior. Field properties control the details of
information, including character or number length, default values, validation rules, captions, and input masks that control
how data gets entered into the field. These properties make it easier to enter and manage data within the field.

CONTROLLING THE SIZE OF TEXT FIELDS


You can control the size of a Text field by setting its Field Size property. A Text field can store from 1 to 255
characters, although the default field size is 50. Be sure you select a field size that will accommodate your data
needs and apply the field size before any data exists for the field. If you reduce the field size for a field that has
data in it, you will truncate data.

STEPS

Changing the Field Size Property for a Text Field

1. Open the table in Design View.


2. Click in the field to select it. The field properties area at the bottom will update to display the available
properties for the data type.

3. Edit the Field Size value.


4. Save the table.

A Text field can store from 1 to 255 characters but a memo field can store up to 65,535 characters.

NOTE!
note

16

Microsoft Access 2010 Intermediate Skills

Making a field larger will have no effect on existing data.

NOTE!
note

Instructions
1. Open the Gourmet Lunch for Data Properties
database.
2. Open the Employees table.
3. Switch to the Design View.
4. Select the State field.
5. In the Field Properties area, click in the Field Size
line.
6. Change the value to 2.
7.

Close and save the table.

8.
9.
10.
11.

Click OK to confirm the new size.


Switch to the Datasheet View.
Click in the State column for the first record.
Try to type more than two characters.

12. Close the table.

17

Comments

There are 20 customer records.


Note that the Field Size property is set to 50.

This will accommodate a two letter abbreviation for


each state.
A message will appear to warn you that some data may
be lost. This message only appears when the field size is
shortened and data exists in the field.

Access will ignore any characters past the two allowed


for the field.

Microsoft Access 2010 Intermediate Skills

CONTROLLING THE SIZE OF NUMBER AND CURRENCY FIELDS


For Number and Currency fields, the Field Size property is particularly important, because it determines the range
of values the field can store. For example, a one-bit Number field can store only integers ranging from 0 to 255.
The Field Size property also determines how much disk space each Number field value requires.
When you enter numeric data into your table, you need to know how Access treats the information, based on the
fields properties. Number properties should be assigned before data is entered into the field to avoid decimal data
being lost.

Number
Field Size

Decimal info
allowed?

Disk space
in bytes

Stores numbers from 0 to 255

No

Stores numbers from 32,768 to 32,767

No

Stores numbers from 2,147,483,648 to 2,147,483,647


(Default)

No

Single

Stores numbers from 3.402823E38 to 1.401298E


45 for negative values and from 1.401298E45 to
3.402823E38 for positive values

Yes

Double

Stores numbers from 1.79769313486231E308 to


4.94065645841247E324
for negative values and from 4.94065645841247E324
to 1.79769313486231E308 for positive values

Yes

12

Decimal

Stores numbers from 10^281 through 10^281

Yes

16

Byte
Integer
Long Integer

Description

STEPS

Changing the Field Size Property for a Number Field


1. Open the table in Design View.
2. Click in the field to select it. The field properties area at the bottom will update to show the available
properties for the data type.

3. From the Field Size drop down list, select the size based on the number of decimal places you need
stored.

4. Save the table.

18

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Entrees table.
2. Click in the Cost field for the first record.
3. Change the price to 9.75
4. Move off the record.
5. Switch to the Design View.
6. Click in the Cost field.
7.
8.
9.
10.
11.
12.

Change the Field Size property to Single.


Change the Format to Currency.
Save the table.
Switch to the Datasheet View.
Change the Cost value in the first record to 9.75.
Move off the record.

Comments
The current price is $10.00
The price changes to $10.00.
The fields data type is Number. The Field Size is set
to Long Integer.
This setting will allow decimal info to be stored.

The price remains at $9.75 because decimal


information is allowed to be stored in the field.

13. Close the table.

SETTING UP DEFAULT VALUES AND REQUIRED FIELDS


There may be times when you find you are typing the same values into a field more often than not. For instance, you might
be tracking patient information and most of the patients you are working with live in the state of Missouri. Rather than
continue to type the state value in every time, you can set a default value for the field and change the value when there is
an exception.

SETTING UP THE DEFAULT VALUE


The Default Value property allows you to specify a value that will be automatically entered when you add a new
record. You can accept the default value or type a new value over it.

STEPS

Adding a Default Value for a Text Field


1. Open the table in Design View.
2. Select the appropriate field.
3. In the Field Properties area at the bottom of the screen, click in the Default Value line.

4. Enter a value.
5. Save the table.

The default value for the field will display in the new record line at the bottom of the table.

NOTE!
note

19

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Lunch Orders table.
2. Switch to the Design View.
3. Select the Order Date field.
4. In the Field Properties area, click in the Default Value
line.
5. Type =NOW()
6.
7.

Save the table.


Switch to the Datasheet View.

Comments

This means every Order Date field entry will be


preloaded with todays date.
Note that todays date is automatically filled in at
the bottom of the table within the new record row.

DESIGNATING REQUIRED FIELDS


By default, only the primary key field in the table is required for data entry because, by definition, it is not allowed
to have a null value or remain blank. However, there are many instances when data is required for other fields. For
instance, patient name fields should not be blank. In a table tracking patient information, the primary key is
assigned to a field that will be unique to each patient, whether it is a patients social security number or another
unique identifier. However, it is possible that two patients could have the same name. This is the reason, in fact,
that the primary key should not be assigned to the name fields. In your patient information table, even though the
name fields are not set as primary, you do want to have as complete a set of data as possible. The Required
property allows you to specify that data must be entered into a field.
Set a required field before entering data into the table. If you are applying this setting to a field that contains data,
Access will warn you that the fields data integrity rules have changed. Access will test the new rule against the
existing data and will warn you if you have records which violate the rule.

STEPS

1.
2.
3.
4.

Setting a Field to be Required for Data Entry


Open the table in Design View.
Select the appropriate field.
In the Field Properties area at the bottom of the screen, click in the Required line.
Select Yes from the drop-down list.

5. Save the table.


6. Click Yes if presented with a message that data integrity rules have changed. Clicking Yes will cause
Access to check each record to see if the rule is valid.

7. Click Yes to continue testing.

20

Microsoft Access 2010 Intermediate Skills

NOTE!

If there is an issue with the data, Access will present another message. At this point, you should cancel the
action, and go back and address the issues in your data.

note

Instructions
1. Open the Lunch Orders table.
2. Switch to the Design View.
3. Select the Main field.
4. In the Field Properties area, click in the Required line.
5. Select Yes from the drop-down list.
Adjust the following fields to be required as well:
Side
Sweet
Drink
7. Save the table.
8. Click Yes to test the changes to the data integrity
rules.
9. Switch to the Datasheet View.
10. Add a New Order but skip the Main field.

Comments

The field record will not be saved unless this field is


filled.

6.

11. Click within another record.


12. Click OK to close the error message.
13. Press ESC to remove the record.
14. Close the Lunch Orders table.

21

It runs a data integrity check.

Use the tab key to quickly pass by the field.


Because Access attempted to save the record and
the Main field was blank, an error message appears.

Microsoft Access 2010 Intermediate Skills

DEVELOPING INPUT MASKS


An input mask is a data entry template for a field. Input masks are often used for data such as social security numbers, zip
codes, or telephone numbers. With an input mask you can control the type and number of characters that can be entered
into the field. For instance, within an input mask applied to a zip code field, you can specify whether letters are allowed,
whether the extended zip code (+4) is required or optional, and whether or not a hyphen is stored with the field. At the
same time, you can assign the Text data type to the field and limit the number of characters stored within the database to
optimize large sets of data. You can also use literal display characters such as hyphens, underscores, or parentheses to give
your users information about what you expect to be entered in the field. Access gives you the ability to choose from a list of
commonly used masks or to create the mask from scratch.

THE STRUCTURE OF AN INPUT MASK


Literal characters

Series of characters

00000\-9999;0;_
Each section is separated by a semi-colon (;).

Placeholder character

There are three sections to an input mask structure:

The first section is the series of characters that makes up the mask. Use F1 within the Input Mask
property to see a complete set of characters.

The second section is used to define whether literal characters (such as parentheses and hyphens) used
within the mask are stored with the value.

The third section is used to identify the placeholder character used to format the field for the data entry
user. The default character used is the underscore (_).

USING THE PRE-DEFINED INPUT MASK


Common masks such as phone number or zip code formats can be applied quickly using the Input Mask Wizard.
The Input Mask Wizard offers a list of pre-defined masks to choose as well as a list of placeholder characters. The
Wizard gives you the choice to store any additional symbols such as the dash in a phone number, with the data or
not.

STEPS

Applying a Pre-Defined Input Mask

1. Open the table in Design View.


2. Select the appropriate field.
3. In the Field Properties area, click in the Input Mask line.
Build button

4. Click the Build button.

22

Microsoft Access 2010 Intermediate Skills

5. Select a mask from the column on the left.

6. Click Next.
7. Select a different placeholder character to display when the user clicks in the field, if desired.

8. Click Next.
9. Choose to store the literal characters in the mask (hyphens, etc.) in the field or to store the data only.

10. Click Next.


11. Click Finish.
12. Save the table.

23

Microsoft Access 2010 Intermediate Skills

Make sure your field size is large enough to store any literal characters you choose to store with the data.

NOTE!
note

Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Click within the Phone field.
4. In the Field Properties area, click in the Input Mask
line.
5. Click the Build button.
6. Click the Phone Number mask.
7. Click in the Try It Line to see how the mask would
appear to data entry users.
8. Click Next.
9. Click Next to accept the underscore character as the
placeholder displayed to the users.
10. Click the With the symbols in the mask option.

11.
12.
13.
14.

NOTE!

Click Next.
Click Finish.
Save the table.
Click the Datasheet View.

Comments

Notice its data type is just text.


Displays the phone field properties.
Opens the Input Mask Wizard.
Type a few letters to see how it reacts.

Storing the literal characters make it easier to read


the phone number but it also takes up more room
within the database file.
Note the syntax used for the mask.
Notice how the phone numbers are now stored.

Setting the InputMask property to the word "Password" creates a password-entry control. Any character typed
in the control is stored as the character but is displayed as an asterisk (*). You use the Password input mask to
prevent displaying the typed characters on the screen.

note

24

Microsoft Access 2010 Intermediate Skills

CREATING A CUSTOM INPUT MASK


When you create a custom input mask, you need to use special characters to represent what type of data, such as
a number or character, you want to display. When you type data in a field for which you've defined an input mask,
the data is always entered in Overtype mode. If you use the BACKSPACE key to delete a character, the character is
replaced by a blank space
You can define an input mask by using the following characters.

Character

Description
Digit (0 to 9, entry required, plus [+] and minus [-] signs not allowed)

9
#

Digit or space (entry not required, plus and minus signs not allowed)
Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but
blanks are removed when data is saved; plus and minus signs allowed)

Letter (A to Z, entry required)

Letter (A to Z, entry optional)

Letter or digit (entry required)

Letter or digit (entry optional)

&

Any character or a space (entry required)

Any character or a space (entry optional)

.,:;-/

Decimal placeholder and thousand, date, and time separators.

<

Causes all characters to be converted to lowercase.

>

Causes all characters to be converted to uppercase.


Causes the input mask to display from right to left, rather than from left to right. You can
include the exclamation point anywhere in the input mask.
Causes the character that follows to be displayed as the literal character (for example, \A is
displayed as just A).

!
\

The following table

Input mask

Sample values

(000) 000-0000

(206) 555-0248

(999) 999-9999

(206) 555-0248

shows some useful

( ) 555-0248

input masks and the

(000) AAA-AAAA

(206) 555-TELE

type of values you

#999

-20 or 2000

can enter in them.

>L????L?000L0

GREENGR339M3
MAY R 452B7

25

>L0L 0L0

T2F 8M4

00000-9999

98115- or 98115-3007

>L<??????????????

Maria

SSN 000-00-0000

SSN 555-55-5555

>LL00000-0000

DB51392-0493

Microsoft Access 2010 Intermediate Skills

STEPS

Creating an Input Mask from Scratch

1. Open the table in Design View.


2. Select the appropriate field.
3. In the Field Properties area, click in the Input Mask line.

4. Type the appropriate syntax for each section of the mask. Separate the sections with a semi-colon.
Instructions
1. In the Employee tables Datasheet view,
click within the first records E ID field.
2. Type 003456 in the E ID field.
3. Press Tab.
4. Click Undo to undo the ID change.
5. Switch to the Design View.
6. In the Field Properties area, click in the Input
Mask line.
7. Press F1.
8. Close the Help screen.
9. Type >LLL - 000000000;1;X in the Input Mask
line.
10. Save the table.
11. Switch to the Datasheet View.
12. Add a new record.
13. Type 00.
14. Type BJC.
15. Type BJC 009873457.
16. Press Tab to move to the next field.
17. Press Esc to cancel the record.

Comments

Accepts any letter or number combination.


The revision is allowed.
The original order number is restored.
E ID field is the first field.

Context-sensitive help on the Input Masks will display.


The >LLL segment requires 3 upper case letters then a
dash and the employee number.

Note the input mask displays Xs as placeholders.


Will not accept numbers.
Will not accept a partial set of information.
Accepts the data set.

? : How could you change the mask to automatically include BJC without typing it?

26

Microsoft Access 2010 Intermediate Skills

DEFINING VALIDATION RULES


Validation rules allow you to restrict or control the data that can be entered into a field. Access will verify that the data
entered into the field is valid as the user leaves the record. If the data entered does not comply with the rule, a message
will appear and the data cannot be saved. When determining a refill quantity for a prescription, you might develop a
validation rule that ensures that the quantity entered for the refill does not exceed the original quantity.

CREATING VALIDATION RULES IN FIELD PROPERTIES


Validation rules are created in the Design Views Field Properties section for a selected field. You can use standard
operators such as >,<,=, and, or, etc. Validation rules can be entered into the Validation Rules Property or you can
use the Expression Builder if you need to add formulas within the rule.

STEPS

Creating a Validation Rule by Typing


1. Open the table in Design View.
2. Click in the desired field.
3. In the Field Properties area, click in the Validation Rule line.

4. Type the rule you want use. (For example: >100 And <1000 or F OR M)
5. Save the table.
Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Select the Gender field.
4. Under the Field Properties, click within the
Validation Rule row.
5. Type F Or M
6. Switch to Datasheet View and save the
changes.
7. Click Yes to test the existing data.
Click Yes to continue to test and keep the
rule.
9. Click within the first records Gender field.
10. Type Female and press TAB.

Comments

Notice it already has data.


Type the rule in the cell.
Dont forget to place quotes around the text.

Allows you to test to see if the existing data fits the new
rule.

8.

11. Retype it as F and press TAB.


12. Close the table.

27

Access displays a message that the value is prohibited


because of the validation rule.
Accepts the data.

Microsoft Access 2010 Intermediate Skills

UNDERSTANDING THE STRUCTURE OF THE EXPRESSION BUILDER


You can use the Expression Builder to create a validation rule for a field. The Expression Builder is also used to help
build formulas, which are called expressions in Access. The Expression Builder allows you to write expressions in
forms and reports, tables, and in queries. It builds a list of fields and controls in your database and displays the
built-in functions. You can create an expression by typing into the Expression box or you can select from the list of
existing expressions. Examples of prebuilt functions include page numbers and the current date.
The Expression Builder contains the following elements:

The Expression Box


Operator buttons
Expression elements
Folders
Categories
Values and Functions

Expression Box

Folders

Values and functions

Definition of the
selected value

Categories

28

Microsoft Access 2010 Intermediate Skills

STEPS

Creating a Validation Rule

1. Open the table in Design View.


2. Click in the desired field.
3. In the Field Properties area, click in the Validation Rule line.

4. Click the Build button.


5. Enter the appropriate validation expression in the Expression Builder.

Click to see a
list of built-in
functions

6. Click OK.
7. Save the table.

EXPLAINING INVALID DATA


The default message that appears when a user enters invalid data can be confusing. You may want to consider
replacing this message with one that explains to the user what type of data is valid for the field.
Heres an example of an error message generated by Access:

29

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Lunch Orders table.
2.
3.
4.

8.

Switch to the Design View.


Click in the OrderDate field.
In the Field Properties area, click in the Validation
Rule line.
Click the Build button.
In the Expression Box, type >=.
Double-click on the Functions folder in the first
column of the Expression Elements area.
Select the Built-In Functions folder.

9.

Select the Date/Time category.

10.
11.
12.
13.
14.
15.
16.

Double-click on the Now function.


Click OK.
Save the table.
Click Yes to perform the data integrity check.
Switch to Datasheet View.
Create a new record but use a date in the past.
Press Tab to complete the record.

5.
6.
7.

17. Click OK.


18. Press ESC twice to cancel the new record.

Comments
You will create a validation rule that ensures that the
order date entered today or in the future.

The Build button will appear.


The Expression Builder window will open.
The Functions folder will expand.
A list of function categories will appear in the middle
column.
A list of date/time functions will appear in the third
section.
The Now function returns the current date and time.
The Expression Builder will close.

A message will appear informing you that the entry


into the OrderDate field is not valid.
The message closes.

30

Microsoft Access 2010 Intermediate Skills

STEPS

1.
2.
3.
4.

Adding Explanatory Text to a Validation Rule Message


Open the table in Design View.
Click in the desired field.
In the Field Properties area, click in the Validation Text line.
Enter meaningful text for the error.

5. Save the table.


Instructions
1. Switch to the Design View.
2. Select the Order Date field.
3. In the Field properties area, click in the Validation Text
line.
4. Type Please enter an order date today or in the
future.
5. Save the table.
6. Switch to the Datasheet View.
7. Create a new record but use a date in the past.
8. Press Tab to complete the record.
9. Click OK to close the message.
10. Change the Order Date to a future date.
11. Press Tab to complete the record.
12. Close the table.
13. Close the database.

31

Comments

This message will appear if the data entered is


incorrect.

The custom error message with appear.

The validation rule is satisfied so the record is


saved.

Microsoft Access 2010 Intermediate Skills

CONTROLLING DATA ENTRY: LOOKUPS


When you provide users a list of choices for a field entry, you eliminate the possibility that incorrect data can be entered. In
Access this can be accomplished by developing a lookup table.

DEFINING A LOOKUP: ENTERING YOUR OWN LOOKUP VALUES


The lookup list can either be built into the field properties as a static list or the list can provide current data from a
table. When your list is static and rarely changes, adding the list to the field is appropriate.

STEPS

Storing the Lookup within the Table

1. Open the table in Design View.


2. Click in the desired field.
3. Change the field type to Lookup Wizard.

4. Click the I will type in the values that I want. option.

5. Click Next.
6. Type the number of columns you want in your lookup list.

7. Click in the first row in Col1.


8. Type the information you want in the list.
9. Press Tab to add additional items in the list. Repeat as needed.

32

Microsoft Access 2010 Intermediate Skills

10. Click Next.


11. If you are listing more than one column, specify which column stores the identifier.

12. Click Next.


13. Type a label for the column. This will show in the datasheet view.

14. Click Finish.


15. Save the table.

33

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Employees table.
2. Switch to the Design View.
3. Add a new text field named HSO.
4.
5.
6.
7.
8.

Change the data type to Lookup Wizard.


Select the I will type in the values I want option.
Click Next.
Enter a 1 for the number of columns.
Press Tab.

9.

Enter the following information in the columns using


TAB after each one:
SLCH
BJH
MBMC
CH
BJHWC
ALTON
BOONE
PROGRESS WEST
Click Next.
Accept HSO as the name of the field.
Click Finish.
Save the table.
Switch to the Datasheet View.
In the first record, click in the HSO field.
From the drop-down list, select BJH.
Close the table.

10.
11.
12.
13.
14.
15.
16.
17.

Comments

In this example, you will create and attach a list of


vendors to the Inventory table.
The Wizard will launch.
Use this option when your list is static.

The Wizard will expand the number of columns


displayed.
Expand the column to view all the text entered.

Note a drop-down list appears.

34

Microsoft Access 2010 Intermediate Skills

DEFINING A LOOKUP: USING A CURRENT TABLES VALUES


When your data is subject to change, you may want to consider keeping your lookup information in its own table.
The table is easier to find and edit than the lookup stored within the field. The table must exist before you can
connect it. In essence, this action will create a relationship between the two tables.

STEPS

1.
2.
3.
4.

Pointing the Lookup to an Existing Table


Open the table in Design View.
Click in the desired field.
Change the field type to Lookup Wizard.
Click the I want the lookup column to lookup option.

5. Click Next.
6. Select the appropriate table.

7. Click Next.
8. Add the appropriate fields from the Available Fields list to the Selected Fields list using the arrow
button.

9. Click Next.

35

Microsoft Access 2010 Intermediate Skills

10. Adjust the width of the column to display the data, if necessary.
11. Turn on or off the viewing of the key column, as desired.
Double-click on the column
border to auto-fit the column
to the data.

12.
13.
14.
15.

Click Next.
Enter a label for your column.
Click Finish.
Save the table.

DELETING THE RELATIONSHIP TO BUILD A LOOKUP


If the field that you want to create a lookup for is in a table that is joined to another table, you will need to delete
the relationship, then you can create the lookup. You can break the relationship in the Relationship window.

STEPS

Deleting a Relationship between Two Tables

1. Click the Database tools tab.


2. Under the Relationships group, select Relationships.

3. If no tables are displayed, click Show Table command and use the CTRL key to select the tables you
want to display.

4. Click OK.
5. Right-click on the table join you want to delete.

6. Select Delete from the shortcut menu.


7. Click Close.

36

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Lunch Orders table.
2. In the first record, click the Employee field.
3. Switch to Design View.
4. Click in the Employee field.
5. Change the data type to Lookup Wizard.
6. Accept the option to look up the values in a table or
query.
7. Click Next.
8. Select the Employees table.
9. Click Next.
10. Add the Employee Last Name field.
11. Click the Selection Arrow.
12. Add the Employee First Name field.
13. Click the Selection Arrow.
14. Sort by Employee Last Name.
15. Click Next.
16. Adjust how wide you want to display the column
and accept the default option to hide the key
column.
17. Click Next.
18. Select Employee Last Name.
19. Accept the Employee Last Name and click Finish.
20. Click Yes to save the table.
21. Switch to Datasheet View.
22. In the first record, click the Employee Name drop
down list.
23. Select an Employee.
24. Close the table.
25. Close the database.

37

Comments
Note the data is simply a number.

Opens the Lookup Wizard.


This option allows you to either enter the list now or
use an existing field in a table as the list source.
Choose from a list of all available tables.

Moves the field to the selected field list.


Moves the field to the selected field list.

Choose which field you want stored in the table.

Note the names are sorted alphabetically.

Microsoft Access 2010 Intermediate Skills

PROPERTY SHEETS
In Access, use properties to determine the characteristics of tables, queries, fields, forms, and reports. You can view
properties in a separate display called a Property Sheet.

WHAT IS A PROPERTY SHEET?


The Property Sheet is a tabbed window that displays on the right side of the Access display. It contains five tabs;
Format, Data, Event, Other, and All. The Property Sheet changes depending on the Access object that is displayed.
If a form or report is displayed then Access allows you to choose to view the properties for the entire object or the
property of a selected element within the object.
Change the object
selected by clicking on
the drop down list.

FORMAT SHEET TABS


The Format tab contains all of the commands related to the formatting and design of the object. The Data tab
contains all of the commands related to where the data on the form is being pulled from and how a user can
interact with that data. The Event tab contains all the commands related to running macros. The Other tab
contains all of the commands that dont fit on the Format, Data, or Event tabs such as the Menu Bar display and
Printing information.

STEPS

1.
2.
3.
4.
5.
6.

Viewing a Property Sheet for Tables and Queries


Open the Access object.
Click the Home tab.
Within the View group, click the View drop-down list.
Choose Design View.
Choose the Query, Table, Form or Report Design tab.
For Queries and Tables within the Show/Hide group, click Property Sheet.

7. For Forms and Reports, within the Tools group, click Property Sheet.

TIME

SAVER

Use the keyboard shortcut F4 to open the Property Sheet quickly.

38

Microsoft Access 2010 Intermediate Skills

USING EXPRESSIONS IN OBJECTS


WHAT IS AN EXPRESSION?
Expressions are a fundamental part of many Microsoft Access operations. An expression is a combination of symbols,
identifiers, operators, and values that produces a result. In Access, the word expression is synonymous with formula.
Sometimes you need information that is not stored in a field in your database. For example, you might need to calculate the
total due from a patient for multiple services or calculate the quantity of a particular drug dispensed within a 24-hour
period. To accomplish these tasks, you use expressions.

Existing field
New Field Name

COST W/TAX:[COST]*1.06
Operator

Example of an
expression located
in an unbound text
box.

RULES WHEN USING EXPRESSIONS


You can calculate in a query, a form, or a report object. Custom calculations can be created referencing particular
table and field names but there are a few rules to remember:

Table and field names must be referred to exactly but case is not considered.

Table and field names must be enclosed by brackets.

Table and field names must be separated by exclamation point.

TIME

SAVER

39

Field names in formulas must be spelled correctly but are not case sensitive.

Microsoft Access 2010 Intermediate Skills

USING EXPRESSIONS IN QUERIES


Expressions are commonly used in queries. If you created a field in a table to hold a total due for a patient visit, you would
be forced to manually calculate that total in an object. Changes to the fees for services would require you to recalculate
that total. Instead, you can create a calculation in a query to total the fees. You can then use that calculation in the report
invoice generated for the patient at the end of the visit. Access also includes the ability to use common functions to quickly
find high level information, such as an average quantity for a drug dispensed by the pharmacy. These are called Aggregate
functions.

USING AGGREGATE FUNCTIONS


Access includes the ability to group and summarize records within a query. By grouping the records, you can
choose from a variety of built-in calculations, including sum, average, and count.

Turn on the Totals


feature and a Total
criteria line will be
added to the query
design grid.

STEPS

1.
2.
3.
4.

Finding a Count of Items


Create a new query in Design View.
Add the appropriate tables to the query.
Add the appropriate fields to the query.
Under the Show/Hide group, click the Totals button.

5. Click in the Total line for the field you want to summarize.
6. Select a function from the drop-down list.

7. Run the query.

40

Microsoft Access 2010 Intermediate Skills

To get the best results with aggregate functions, use the fewest number of fields possible.

NOTE!

note

Instructions
1. Open the Gourmet Lunch for Expressions database.
2. Create a new query in Design View.
3. Add the Employees, Lunch Orders, and Entrees tables to
the query.
4. Add the Employee Last Name field from the Employees
table to the query.
5. Add the Main field from the Lunch Orders table to the
query.
6. Sort the Employee Last Name field in Ascending order.
7. Click the Totals button.
8. In the Total line for the Main field, choose Count from
the drop-down menu.
9. Run the query.

Comments

Note that the tables are already related.

A Total line is added to the query grid.

For each product in the Inventory table, you will


see the number of customers who ordered it.

10. Resize the columns to view the entire set of data.


11. Save the table as Orders by Employee.
12. Close the query.

Q?: What is another way to get a count of how many orders per employee?

CREATING CUSTOM CALCULATIONS


When you create a custom expression in a query, you create a field that can be used in forms or reports. This
allows you to extend your data without storing manually calculated information in a table.
In the query grid, the calculated field consists of three parts: the name you'll give to the calculated field, a colon,
and then the expression that generates the result of your calculated field.
New Field Name

Existing Field (in brackets)

COST W/TAX:[COST]*1.06
Operator

41

Microsoft Access 2010 Intermediate Skills

STEPS

Creating a Custom Calculation in a Query

1. Create a new query in Design View.


2. Click in a blank field cell in the query grid.
3. Type a name for the expression, followed by the colon (:). Type the expression for the calculation,
referring to the rules outlined in the Using Expressions section.

4. Right click on the field cell.


5. Choose Properties from the short-cut menu or press F4.
6. Select an appropriate format.

7. Run the query.


Instructions
1. Open the Orders by Dept query.
2.
3.

Click in the first blank Field cell.


Type Cost w/tax:[Cost]*1.06

4.
5.
6.
7.
8.

Run the query.


Switch to the Design View.
Right-click on the Cost w/tax field.
Select Properties.
Choose Currency from the Format drop-down
menu.
Run the query.

9.

Comments
Note that there are many items that have quantities
ordered greater than one.
Be sure to spell the fields correctly and use the bracket
symbol not the brace.
Note that the Cost w/tax field has a general number format.
A short-cut menu will appear.
The Format property is found on the General tab.
Note that the Extended Price field has a general number
format.

10. Save the query.


11. Close the query.

How Can I get a Total for the ID department?

42

Microsoft Access 2010 Intermediate Skills

USING EXPRESSIONS IN FORMS


You can also add an expression directly to a form. For example, you might use a calculation to total fees from multiple
fields. An unbound text box is used to hold the expression. The expression is entered into the text boxs Property Sheet
under the Control Source. Expressions in forms look for like an Excel formula because they start with an equal sign.

CALCULATING IN A FORM BY ADDING A TEXT BOX


You can add text boxes to any form or report in either Design or Layout View. When a text box is added, it will not
only create a text box but also a label box. The text box will display the word unbound in the box. This means
that this text box is not bound to any particular field within the database.
Unbound text box
with label
Text boxes can be bound to a field or contain an expression that includes reference to a field. Expressions in forms
are added within the Control Source of an unbound text box. You can use the Expression Builder to create the
expression and then it will display in the Property Control Source box.
Expression can be
typed in within the
Control Source line.
Choose the values
format

STEPS

Adding an Expression to a Form


1. Open the form in Design View.
2. Click the Form Design Tools Design tab.
3. Under the Controls group, click the Text box button.

4. Click and drag on the form where you want the text box to appear.
5. Select the unbound object.
6. Click the Form Design Tools Design tab.
7. Under the Tools group, select the Property Sheet.

8. On the All tab, type a name for the object in the Name line.
9. In the Control Source line, type the expression or use the Build button to open the Expression Builder.

10. In the Format line, choose an appropriate format using the drop-down list.

43

Microsoft Access 2010 Intermediate Skills

11. Select the label.


12. Click the All tab.
13. Under Caption, type a name for the label.

14. Press Enter.


15. View the form to test your expression.

TIME

SAVER

You can also right-click on an unbound object to access the Property Sheet.

ADJUSTING THE TEXT BOX AND LABEL BOX LOCATION AND SIZE
The text box and corresponding label box are both attached by default. You can adjust the individual box size by
using the selected boxs size handles. If you need to move both boxes to a new location, simply click and drag one
of the boxes and the other will also move. Use the larger black handle on either the label or text box to move
them individually.
The larger square
handle is to move the
label only

Instructions
1. Open the Gourmet CO Orders form.
2.
3.
4.
5.

Switch to Design View.


Click the Form Design Tools Design tab.
Under the Controls group, click the Text Box tool.
Click below the Cost field.

6.
7.
8.
9.

Move the unbound control to align it with the


Cost field, if necessary.
Right-click on the unbound object.
Choose Properties from the short-cut menu.
Click in the Control Source line.

10.
11.
12.
13.
14.
15.
16.

Type = [cost]*1.06.
Click in the Format line.
Select Currency from the drop-down list.
Close the Properties window.
Switch to the Form View.
Save the form.
Close the form.

Comments
Note that the form contains a subform with order
details.

The mouse pointer will change to include Text Box icon.


Use the crosshair located at the top left of the mouse
pointer to help you position the field. An unbound
control will be added.

The Control Source property can be found on the All or


the Data tabs.

You will need to scroll down.


Note the calculation.

44

Microsoft Access 2010 Intermediate Skills

USING EXPRESSIONS IN REPORTS


You can use expressions from queries in reports or create expressions directly within the report. Examples of common
report expressions include a grand total for an invoice or claim, merged text fields storing name and address information,
page numbers and date/time information.

CREATING AN EXPRESSION IN A REPORT


In order to place an expression in a report you will need to be in Design view. Just like with forms, you can type an
expression in the Property Sheet of an unbound object within the Control Source.
Example of an
expression located in
the property sheet.

Example of an
expression located in
a reports unbound
text box.
STEPS

Adding an Expression to a Report


1. Open the report in Design View.
2. Click the Report Design Tools Design tab.
3. Under the Controls group, select the Text Box tool.

4. Using the Text Box tool, add an unbound control to the report in the section in which you want the
5.
6.
7.
8.

expression to appear.
Right-click on the unbound object.
Choose Properties from the short-cut menu.
On the All tab, type a name for the object in the Name line.
In the Control Source line, type the expression or use the Build button to open the Expression Builder.

9. In the Format line, choose an appropriate format using the drop-down list.
10. Close the Properties window.
11. Update the label object with descriptive text.
12. View the report to test your expression.

TIME

SAVER

45

You can use the keyboard combination Shift + F2 to open a Zoom window. This window will allow you to
enlarge the font size, making it easier for you to create and edit the expression.

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Orders by Dept report.
2. Switch to the Design View.
3. Click the Report Design Tools Design tab.
4. Under the Control group, click the Text Box tool.
5. Add the unbound control box to the Dept Footer
section below the Summary for text box.
6. Under the Tools group, click the Property Sheet.
7. Under the Property Sheets Data tab, click in the
Control Source line.
8. Press Shift + F2 on the keyboard.
9. Change the Font command button.
10. Change the font size to 12.
11. Click OK.
12. Type=Sum([Cost]*1.06.
13.
14.
15.
16.
17.
18.

Press ENTER.
Select the label and type Sum with Tax.
Press ENTER.
Click OK.
Click in the Format line.
Select Currency from the drop-down list.

Comments
Notice how the report is divided into sections.

The text box Property Sheet opens on the right.

The Zoom window will open.


Allows you to change the font size so its easier to see.
This affects text within the Zoom window only.
This formula adds together all the field values in the
group and then multiplies them by 1.06.

Formats the value to display a dollar sign and two


decimal places.

19. Close the Property Sheet.


20. Preview the report.
21. Save the report.

46

Microsoft Access 2010 Intermediate Skills

CONCATENATING TEXT
The word concatenate means to combine. Concatenating text is handy when you need to display fields together
in a report such as a First and Last Name. Access uses the plus sign (+) as the concatenation symbol. All literal
characters, such as spaces and punctuation, must be enclosed in quotation marks.
Concatenation symbol

STEPS

1.
2.
3.
4.

Literal characters are in quotes

Merging Text Fields in a Report


Open the report.
Right-click on the report and select Design View.
Click the Report Design Tools Design tab.
Under the Controls group, select the Text Box tool.

5. Using the Text Box tool, add an unbound control to the report in the section in which you want the
6.
7.
8.
9.

expression to appear.
Right-click on the unbound object.
Choose Properties from the short-cut menu.
On the All tab, type a name for the object in the Name line.
In the Control Source line, type the expression or use the Build button to open the Expression Builder.

10. Type the next text or field name.


11. Under the Views group, click the Report View or Print Preview button.

47

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Orders by Dept report.
2. Switch to Design View.
3.
4.
5.
6.

7.
8.
9.
10.
11.
12.
13.
14.

Under the Detail Section, delete the Employee


Last Name and Employee First Name fields.
Click the Report Design Tools Design tab.
Under the Controls group, select the Text box
tool.
Add the unbound control within the Detail
section lined up with Employee First Name field in
the Page Header.
Type =[Employee Last Name]+,+[ Employee
First Name].
Switch to Report View.
Switch to Design View.
Select the text label and press DELETE.
Under the Page Header section, delete the
Employee First Name text box label.
Select the Employee Last Name text box label and
remove the word Last.
Press ENTER.
Select the concatenated text box, and
add a space after the comma.

15. Right-click on the report and select Design View.


16. Make adjustments to the size and position of the
bound control, if necessary.
17. Switch to Report View.
18. Close the report and save the changes.

Comments
Note that the report opens in Print Preview.
You can right-click on the open report and choose
Design View.

Make it big enough to accommodate both first and last


names.
Dont forget the brackets!
Displays a Print Preview of the report.
Click the larger selection handle to delete just the label.

Select the text box and then double-click on Last to


quickly select it.
Accepts the change.
In some cases spaces needed to be added when
combining fields. Access doesnt automatically add
them.
Offers a quick way to switch to Design view.

48

Microsoft Access 2010 Intermediate Skills

OTHER TYPES OF QUERIES


QUERY OPTIONS
Most queries used in Access are Select queries; this type of query extracts information from the table or tables used within
the query based on the criteria set. Although you can use a Select query to change data in a table, no other action takes
place. There are other types of queries as well, including a Make Table query, an Update query, an Append query, Delete
query and Parameter query. These queries take action on your data.
To create these special queries you need to start with a Select query. When the select query is in Design View, then the
Query Tools tab appears which contains the Query Type group.
Run command is
important tool with
specific queries.

Updates values

Pushes data to a
new table.

Deletes specific data from a table

Pushes data to
an existing table.

UPDATE QUERIES
An Update query is used to make changes in the data of a table. An Update query might be used if fees are increased (or
reduced) by 5% across a group of services. Rather than calculate the new fee manually and revise the records, an Update
query can calculate the entire fields data within a table. In order to run an Update query, you must use the Run button on
the toolbar. No action takes place when you use the View button.

STEPS

1.
2.
3.
4.
5.
6.
7.

Running an Update Query


Create a new query in Design View.
Add the appropriate tables to the query.
Add the desired fields to the query. The field being updated must be added to the query.
Add criteria to the query specifying which records are affected.
Run the query to verify you are returning the records you want to affect.
Switch to the Design View.
Click the Query Tools Design tab.

8. Select Update Query. An Update To line will be added to the query grid.

49

Microsoft Access 2010 Intermediate Skills

9. Enter an expression in the field you want updated.

10. Click the Run button.

11. Click OK to confirm the action.


12. Close the query without saving.

NOTE!

Saving an update query can be dangerous! The query will run when someone double-clicks on it, which will
cause the update to occur again.

note

Instructions
1. Open the Entrees table.
2. Close the table.
3. Create a new query in Design View.
4. Add the Entrees table to the query.
5. Add the SW and Cost fields.
6. In the Main criteria line, type *wrap.
7. Run the query.
8.
9.
10.
11.
12.
13.
14.

Switch to Design View.


Click the drop-down arrow to the right of the
Query Type tool.
Select Update Query.
In the Update To line for the Cost field, type
[Cost]+1.50.
Click the Run button.
Click Yes to confirm the action.
Close the query without saving.

15. Open the Entrees table.


16. Close the table.
17. Close the database.

Comments
Notice the prices of the wraps.

Displays only descriptions that end in wrap.


There are 4 items with the SW field equal to Wrap.
Note the prices of each.
A list of other query types will display.
An Update To line will be added.
This will increase the price of each wrap by $1.50.

If you saved and reran the query the prices would


increase again.
Note the new prices.

OH NO! - Why is the Cost increase more than just $1.50?

50

Microsoft Access 2010 Intermediate Skills

MAKE TABLE QUERIES


A Make Table query is often used to segment data into separate tables. For instance, you might use a Make Table query to
archive old patient visit records in order to improve the performance of your Visits table. Then you can delete the old
records from the visits table and be assured that they are stored elsewhere in the database.

STEPS

Running a Make Table Query

1.
2.
3.
4.
5.
6.
7.

Create a new query in Design View.


Add the appropriate tables to the query.
Add all fields you want in the new table.
Add criteria to the query specifying which records will be added to the new table.
Run the query to verify you are returning the records in the new table.
Switch to Design View.
Click the Query Tools Design tab.

8. Run the query.


9. Type a name for the new table.

10.
11.
12.
13.

If you want to the table to be stored in a new database, select the database.
Click OK.
Under the Results group, select Run.
Click Yes to confirm the action.

14. Close the query without saving.

51

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Employees table.
2. Close the table.
3. Create a new query in Design View.
4. Add the Employees table to the query.
5. Add all the fields individually to the query.
6. In the Inactive criteria line, type Yes.
7. Run the query.
8. Switch to the Design View.
9. Click the Query Tools Design tab.
10. Under the Query Type group, select Make Table
query.
11. Type Inactive Employees as the table name.
12. Under the Results group, click Run.
13. Click OK.
14. Click Yes.
15. Click Yes.
16. Close the query without saving.
17. Open the Inactive Employees table.
18. Close the table.

Comments
Note how many inactive employees display.

How many inactive employees are there?

Changing the View will not run a Make Table query.


Closes the Make Table dialog box.
Confirms the action.
Confirms pasting rows into the new table.
How many records display in the new table.

52

Microsoft Access 2010 Intermediate Skills

APPEND QUERIES
An Append query adds records to an existing table. You might receive a report on new patients from another department
and would like to add these patients automatically to the existing Patients table. You must first make sure that all of the
required data is present in the records you wish to append.

STEPS

1.
2.
3.
4.
5.
6.
7.
8.

Running an Append Query


Create a new query in Design View.
Add the appropriate tables to the query.
Add all fields you need to append.
Add criteria to the query specifying which records will be added to the existing table.
Run the query to verify which records will append.
Switch to Design View.
Click the Query Tools Design tab.
Under Query Type, click Append.

9. Click the Table Name drop down list and select the table you want to append.

10. If you want to the table to be stored in another database, select the database.
11. Click OK.
12. Under the Results group, select Run.

13. Click Yes to confirm the action.


14. Close the query without saving.

53

Microsoft Access 2010 Intermediate Skills

Instructions
1. Open the Employees table.
2. Select two records and mark them Inactive.
3. Close the table.
4. Create a new query in Design View.
5. Add the Employee table to the query.
6. Add all the fields individually to the query.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.

In the InActive criteria line, type Yes.


Run the query.
Switch to the Design View.
Under the Query Type group, select Append
Query.
Select Inactive Employees from the Table Name
drop-down list.
Click OK.
Under the Results group, select Run.
Click OK to confirm the append action.
Close the query without saving.
Open the Inactive Employees table.
Close the database.

Comments
Click in the Yes/No checkbox.

To save time, select all the fields first and then drag and
drop them into the design grid.
Yes or True means checked.
Check the results.
The Append window will open.

Appends the table with the new data.

Note how many employees are now listed.

54

Microsoft Access 2010 Intermediate Skills

DELETE QUERIES
When you need to remove a small amount of records from a database its safest to simply open the table or form that
displays the records and use the Delete command. But if you need to delete large amounts of data quickly, use a Delete
query. Delete queries remove all the data in each field, including the key value that makes a record unique.
If you wish to use the Delete query to remove records from multiple tables rather than just a single database table, you will
need to ensure that:

You have relationships defined between related tables in your Microsoft Access database
You have enforced the Referential Integrity for the relationships between your chosen tables.
You have opted to Cascade Delete Related Records for the relationship type

If you are using the Delete query to remove records from multiple tables that are related in a One-To-Many relationship
without having defined the option to Cascade Delete Related records, Microsoft Access will only delete the records from
one table at a time. If this is the case, you must delete the records from the many side of the relationship first (to ensure
against orphaning records), and then delete the records from the one side of the relationship.

Make sure that you have a backup of your database before you delete your data.

NOTE!
note

STEPS

1.
2.
3.
4.
5.
6.
7.

Running a Delete Query


Create a new query in Design View.
Add the appropriate tables to the query.
Add all fields you want to delete.
Add criteria to the query specifying which records will be deleted.
Run the query to verify which records will be deleted.
Switch to Design View.
Click the Query Tools Design tab.
Under Query Type group, click Delete.

8. Click Yes to approve the delete.

9. Close the query without saving the changes.

55

Microsoft Access 2010 Intermediate Skills

Instructions
1. Create a new query in Design View.
2. Add the Employees table to the query.
3. Add all the fields individually to the query.
4. In the Inactive Employee criteria line, type Yes.
5. Run the query.
6. Switch to the Design View.
7. Under the Query Tools Query Type tab, select the
Delete Query.
8. Click Yes.
9. Close the Query and dont save it.

Comments

Yes or True means checked.


The results display only the Inactive Employees.

Approves the record deletion.

56

Microsoft Access 2010 Intermediate Skills

PARAMETER QUERIES
Sometimes we need to use the same basic query on a monthly basis but one variable needs to be adjusted each time.
Instead of recreating a new query each time or changing the design of an existing one, you can build a Parameter query.
This useful query asks for your input to set criteria before the query actually runs.
Instead of typing a value or expression into the criteria cell in Design view like a normal query, you type your question in the
criteria cell and enclose it in square brackets ([ ]).
Adding brackets to the
value or expression
will set it as a
parameter message.

The text you type will appear as a prompt on a dialog box, so you might want it to be in the form of a question to the user.
In this example the user will be prompted to type the name of a department when they run the query. The text the user
types will be used as the criteria for that particular field. The dialog box looks like this
When the message
appears, type in your
criteria.

STEPS

57

Creating and Running a Parameter Query

1.
2.
3.
4.

Create a Select Query in Design View.


Add any non-variable criteria to the appropriate fields in the Criteria row.
Locate the field(s) you would like to make variable criteria.
Type the phrase you would like to appear in the prompt that will pop up every time you run your
query. Enclose the phrase in brackets [].

5.

Under the Results group, click Run.

6.

A dialog box will appear with the prompt you specified.

7.

Enter your criteria and click OK.

Microsoft Access 2010 Intermediate Skills

TIPS FOR WRITING PARAMETER QUERIES

Ideally, the prompt you create for your query should make it clear what type of information the search
term should be, and what format it should be entered in. For example, to guarantee that people enter a
search for a date in the format we use in our database, we could write the following in the Criteria: row of
the Date field: [What date? (mm/dd/yy)] .

The simplest parameter query will give you an exact match criteria, meaning that the query will search for
the exact text you enter in the prompt. However, you can turn any type of criteria into variable criteria.
Simply type your prompt text in brackets in the part of the criteria where you would normally put a search
term.
For example, in a normal query, we could find orders that were placed between two dates by using the
criteria Between x AND y, and replacing the x and y with the first and second dates, respectively. To turn
this into a parameter criteria, we would simply replace the x and y with the text we want to appear in the
prompt. Our variable criteria might look like this: Between [Enter the start date:] AND [Enter the ending
date:]. These prompts would appear:

Instructions
1. Open the Orders by Date query.
2. Within the Order Date field criteria line, type [What
Date?]
3. Press Enter.
4. Switch to Datasheet View.
5. Type 5/15/2013 and click OK.
6. Switch to Design View.
7. Within the Order Date field criteria line, remove the
current parameter.
Replace with the following:
Between [Enter Start Date:] and [Enter End Date:]
8. Press Enter.
9. Switch to Datasheet View.
10. Enter a Start Date and click OK.
11. Enter an End Date and click OK.

Comments

Runs the query with the parameters.

Adding the Between and And operators creates


multiple parameter criteria boxes.

58

You might also like