78
For Evaluation Only Microsoft Access 2013 Relationships, Queries, Forms and Reports Supports: Access 2013 Access 2010 Jeff Hutchinson Excel Networks www.excel-networks.com

Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

Embed Size (px)

Citation preview

Page 1: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Microsoft Access 2013

Relationships,

Queries, Forms

and Reports

Supports:

Access 2013

Access 2010

Jeff Hutchinson

Excel Networks

www.excel-networks.com

Page 2: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 1

Access 2013 - Level 2 Relationships, Queries, Forms, Reports

Access database administrators that have database creation skills need in-depth knowledge of Relationships, Queries, Forms and Reports. Relationships between tables will include Reverential Integrity to make sure errors between tables do not occur. Queries are the source for Forms and Reports. A Query will find and generate the data needed and the Form or Report will format it and make it look presentable. We will cover different ways to generate a Query using wild characters, filters, operators, expression builder, parameters, concatenation, and action queries. We will also learn how to create a Form and customize its control properties. In the Reports section of the course, we will cover how to format, controls, Design View, and Report Wizard. This course will also cover how to customize database components, Export, Import and Link to other data sources. This book is designed in conjunction with an Online-Instructor-Led course (for more information see: www.excel-networks.com). Unlike other manuals, you will not need to review lengthy procedures in order to learn a topic. All you will need are the brief statements and command paths located within the book to show you how to use a concept. Furthermore, you will find that this book is often used as a reference to help comprehend a concept quickly, and an index is provided on the last page of the book to reference pages as necessary. However, if more detail is needed, you can always use the Internet to search a concept. Also, if your skills are weak due to lack of use, you can refresh your memory quickly by visually scanning the concepts needed and then testing them out using the application.

Table of Contents Chapter 1 - Relational Integrity Databases .................................................................. 3 Chapter 2 - Advanced Database Design ..................................................................... 14 Chapter 3 - Export, Import and Linking Tables ....................................................... 20 Chapter 4 - Operators in Queries ............................................................................... 24 Chapter 5 - Advanced Queries .................................................................................... 32 Chapter 6 - Action, Crosstab, And Duplicate Queries .............................................. 40 Chapter 7 - Form and Report Design ......................................................................... 50 Chapter 8 - Advanced Form Design ........................................................................... 62 Chapter 9 - Advanced Report Design ......................................................................... 70 Appendix A - Naming Conventions ............................................................................ 76 Access 2010/2013 Level 2 Index .................................................................................. 77

Copyright and Release Information This document was updated on 9/19/2016 and is designed for Access 2013. The document is suitable for using Access 2010 and Access 2013. The material is the sole property of Jeff Hutchinson and Excel Networks. Any emailing, copying, duplication or reproduction of this document must be approved by Jeff Hutchinson in writing or Email. However, students who take a class or purchase the material can use this document it for personal development and learning.

Page 3: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 2

Exercise Download Exercises are posted on the web site and can be downloaded to your computer. Please do the following: Open Internet Explorer.

Type the web address: excel-networks.com/download/access2013-2.exe You might get several security warnings, but answer yes and run through each one. When you click “Unzip,” the files will be located in C:\Data\Access2013-2 folder.

If there are any questions or problems, please contact Jeff Hutchinson at: [email protected] Note: For Mac users, download the file at: excel-networks.com/download/access2013-2.zip

About the Author Jeff Hutchinson is a computer instructor teaching a variety of classes around the country. He has a BS degree from BYU in Computer Aided Engineering and has worked in the Information Technology field supporting and maintaining computers for many years. He also owned a computer training and consulting firm in San Francisco, California, and after selling his business in 2001, he has continued to work as an independent computer instructor in California and Utah. Mr. Jeff Hutchinson lives in Utah and provides training for the Utah Valley University Community Education system, offering valuable computer skills for the general knowledge of students, career development, and career advancement. Understanding the technology and the needs of students has been the basis for developing this material. Jeff Hutchinson can be contacted at [email protected] or (801) 376-6687.

How This Book Is Organized This book begins with some basic concepts and the later chapters provide more advanced information. The following are special formatting conventions:

Numbered Sections on the left are the Concepts. Italic Text is used to highlight commands that will perform the concept or procedure in

completing the practice exercises. Practice Exercises are a Step-by-Step approach to performing the concept. Student Exercises are an Independent approach to performing the concept. Dark, Grayed-Out Sections are optional/advanced concepts.

Bolded items are ribbons or commands used.

Page 4: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 3

Chapter 1 - Relational Integrity Databases In this chapter, you will learn how to manipulate columns, Insert Hyperlinks, and create Many-To-Many Relationships.

Concept Explanation / Command String in italic. Practice Exercise 1 File TabOpenRelationshipAll.accdb to review the relationships in the

example below. Create a Query Design and add tblCustomers table (add fields Store and City) and tblOrders table (add field Description) to the Query fields. Run the Query showing all the orders associated with the customer.

1.1 Join Related Tables

Tables can be joined and related, in order to access information in all the fields of the related tables. Joining tables will allow you to create reports, forms, and queries from the related data tables. This also involves breaking up data into smaller, more efficient tables that can be referenced when you need access to data. However, the tables must have a common join field that contains the same type of data. For example, the following table consists of customer names and address fields, along with a unique identification number for each customer, the ID# will serve as the primary key in the table. tblCustomers

You could then create a separate table consisting only of orders placed by customers. This table would also contain the field for the unique customer identification number. tblOrders

By relating the two tables through the common customer identification number field, the customers’ name and address does not have to be entered for every order. All that has to be entered, then, is the customer identification number, along with the orders.

Page 5: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 4

1.2 Primary Key

This is a fundamental aspect that binds tables together. All the records in the field must be unique (not duplicated). This unique identifier could be driver’s license number, studentID, etc, but is usually a unique autonumber which increments automatically as new records are entered. Each table can have only one Primary Key.

1.3 Foreign Key

This key, related to the Primary Key, is located in another table. The Primary Key in one table connects to the Foreign Key in the related table. The Primary and Foreign Keys are the same record type and connected through a link. One exception to this rule, however, is if the Primary Key is an AutoNumber. The Foreign Key should then be a number datatype.

1.4 Multi-Field Primary Key

Here, the Primary Key is composed of multiple fields. This does not mean you can have a table with two Primary Keys. Instead, it means you can create one Primary Key that is composed of two fields. For example, First and Last names together create a Primary Field, but alone they are insufficient to be a Primary Key. Usually, a Unique ID is created and a Multi-Field Key would only be used on an existing database that has no Unique ID available.

1.5 Relationship Window

The Relationships Window displays a graphic representation of the database and allows you to create relationships between tables.

Database Tools Ribbon TabRelationships Button .

1.6 One-to-One Relationship

A One-To-One Relationship occurs when one record from the Primary Table matches one record from the related table. Access determines the relationship type automatically when the relationship is created.

For example, suppose you have a database that tracks employees and their emergency contact information. These tables might include the following records. Notice that for each record in the tblEmployees Table there is a corresponding record in the tblEmergency Contact Table. This is a one-to-one relationship.

tblEmployee tblEmergencyContact

Note: A One-To-One relationship can also be established between a secondary table with many relationships. The system will still establish a One-To-One Relationship between each one-to-one relationship. File TabOpenRelationshipAll.accdb to view the above relationships.

Page 6: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 5

Practice Exercise 2 To create a relationship, select the key record, hold the left mouse button down,

drag the key field to the Foreign Key in another table. If the names are different, it will still work as long as the data and the data type is the same. 1. File TabOpenRelationshipAll.accdb.

2. Database Tools Ribbon TabRelationship Button Show Table. 3. Drag the tblClient Table/ClientID to tblProjects Table/ClientID.

1.7 Deleting A Join Line

Deleting A Join Line removes the relationship between two tables. You may want to delete a join line if you no longer need to relate the tables or if you want to create a different relationship. You must select a Join Line before you can delete it and then press the [Delete] Key.

Practice Exercise 3 Continue with previous Practice Exercise.

1. Select the Relationship Button in the Database Tools Ribbon Tab. 2. Select the middle line segment of the Join Line between the tblCustomers and tblOrders field lists. 3. Press [Delete] KeySelect .

1.8 One-to-Many Relationships

A One-To-Many Relationship occurs when one record from the Primary table matches many records from a related table. For example, in a database that tracks sales people and their customers you might have the following tables. Notice that for each record in the Sales Reps table there can be multiple corresponding records in the Customers table.

tblSalesRep

tblCustomers

A Key Field is required to link the tables together. In this example, the RepID is the Primary Key in the tblSales Rep Table, and the Foreign Key in the tblCustomer Table.

File TabOpenRelationshipAll.accdb to view the above relationships.

Click Here.

Page 7: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 6

1.9 Join Type The Join Type will establish the One-To-Many Relationship. For example, the “All” in the Join Type dialog box (below) indicates the Many, the word Only indicates the One in a One-To-Many relationship.

The 1 on the left side indicates a One-To-One Relationship.

Practice Exercise 4 Create a relationship between CustomerID’s. 1. File TabOpenRelationshipAll.accdb. 2. Database Tools Ribbon TabRelationships Button. 3. Drag the tblCustomer/CustomerID to tblPurchase/CustomerID. 4. If necessary, Double click on the link line between the CustomerID’s. 5. Choose Join Type. 6. Choose Join Type option 3 and set the One-To-Many relationship. (See the Join properties above)

Practice Exercise 5 This will allow a Product Table to have a relationship with the purchase. There will be one product and many purchases associated with the Product Table. This will be a Many-To-One relationship. 1. Link the ProductID between the tblPurchase and tblProduct tables.

1.10 Junction Tables

A Junction Table is used to connect or join two Many-To-Many related tables together. A Junction Table name will have a prefix of tjn. Example: tjnLineItems.

1.11 Many-to- Many Relationship

A Many-To-Many Relationship occurs when a number of records from the Primary Table match a number of records in the related table (when dealing with Products and Orders, each record in the Orders table may match many records in the Products table and vice versa).

The proper way to create a Many-To-Many Relationship is to create a third table called a Junction Table. The Junction Table has two Foreign Keys, one from each table and will relate to a table with a Primary Key.

This setup demonstrates that a Many-To-Many Relationship is really two separate One-To-Many Relationships. The first One-To-Many in the example above is tblOrders to tblLineItems (one order may have many line items). The second One-To-Many example is between the products and the tblLineItems (one product is hopefully sold many times). Without the Junction Table, it is impossible to create a Many-To-Many Relationship.

Page 8: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 7

Practice Exercise 6 1. File TabOpenRelationshipAll.accdb. 2. Database Tools Ribbon TabRelationship ButtonShow Table. Add tblCustomers, tblOrders, tjnLineItems, and tblProduct, if necessary. 3. Set the Primary Key Right-Click on each table and set the following Primary Keys in the Design View: tblCustomers/ID#, tblOrders/OrderID, and tblProducts/ProductID 4. Drag the tblCustomer/ID# to tblOrders/ID#. 5. Set the Join Type 3 to a Many Orders to one Customer. 6. Drag the tblOrders/OrderID to tjnLineItem/OrderID. 7. Set the Join Type 3 to a Many line Items to one Order. 8. Drag the tjnLineItems/ProductID to tblProducts/ProductID. 9. Set the Join Type 3 to a Many line Items to one Product. 10. Optional: Set Primary Key in the tblSalesRep and Join the tblSalesRep/RepID field with tblCustomers/RepID field.

1.12 Orphan Records

In a database, if a record has no related records it is considered an Orphan. For example, an order may relate to a customer that does not exist. This could occur by a poor database design that allowed it by typing the record in manually, or the data was extracted from another source (Excel) that had missing records.

Practice Exercise 7 Orphan Records

See the section on “Find Unmatched Query Wizard” to identify Orphans in a table.

1.13 Referential Integrity

When you create a Relationship between two tables, you can set Referential Integrity. Referential Integrity is a built-in set of rules that Access uses to make sure the relationship is valid, stores accurate information, and prevents database Anomalies (the ability to enter in records that are wrong). Referential Integrity can also prevent accidental deletion or editing of data. In order to use Referential Integrity, the following conditions must be true: the related field in one table must have a Primary Key, and the related fields in both tables must have the same data type and Property Value. When Referential Integrity is enforced, Access displays symbols above the Join Line to indicate the type of relationship: One-To-One or One-To-Many. The number 1 above a Join Line indicates “one,” and the mathematical symbol for infinity ∞ indicates “many.”

1.14 Cascade Update

Cascade Update will allow all related records to be updated if the Key Field is changed. Allowing this change without Referential Integrity will create Orphan records in the related tables. In other words, if you change the ID#, the system will Cascade Update the ID# in the tblOrders table.

Page 9: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 8

1.15 Cascade Delete

Cascade Delete will allow all related records to be deleted if the Key Field is deleted. Allowing this change without Referential Integrity will create Orphan records in the related tables. In other words, if you delete a Customer record, all related records will be deleted. This could become a dangerous feature and should be carefully considered when used.

Practice Exercise 8 Continue from the previous exercise (RelationshipAll.accdb) 1. Open the Relationships Window (Database ToolsRelationship button) 2. Double-click the middle segment of the join line between the tblCustomers.ID# and tblOrders.ID#. 3. Select Enforce Referential Integrity 4. Select Enforce Referential Integrity for the join between the other tables. Note: in order to Enforce Referential Integrity you must: Delete the following records in the tblCustomers table: 1837, 2599, 3998, 5999. Delete the following records in the tblOrders table: 1107, 1163, 1363, 1730, 1817.

5. Close the Relationships window.

Student Project A - Database Relationships (Referential Integrity)

In this exercise, you will create relationships and set Referral Integrity. This simplified example will create everything from a blank database. You will be able to see how Referential Integrity works and what happens when Orphan records are introduced. Later, we will test Cascade Update and Delete. 1. Create the Database and Tables.

1A. Create the Database 1A-1. Create a new DB. 1A-2. Save it as RDExample. 1B. Create the first table 1B-1. Create ribbon tabTable Design button. 1B-2. Enter the following field names: 1B-3. Set the Primary Key to CustomerNum.

1B-4. Save the table as tblTable1. 1C. Create the second table 1C-1. Create ribbon tabTable Design button. 1C-2. Enter the following field names: 1C-3. Set the Primary Key to OrderNum. 1C-4. Save the table as tblTable2.

Page 10: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 9

Note: Access 2010 use Text Datatype.

2. Set up the Relationships to No Integrity

2A. Set the Relationships 2A-1. Database Tools ribbon tabRelationships button. 2A-2. Add the two tables to the relationships screen. 2A-3. Create the relationship by dragging CustomerNum in tblTable1 to CustomerNum in tblTable2.

2A-4. Specify the Join Type.

2A-5. Specify the join type as #3

2A-6. OKOKClose the Relationships screen

3. Enter Data

3A. Open the tblTable1 and enter in the following data:

3B. Open tblTable2 and enter in the following data:

3C. Referring to Customer Number 3 in tblTable2 There is no customer 3 record located in tblTable1. This is a violation of Referential Integrity and is an Orphan Record. Access allowed record 3 to be entered because no integrity has been set up.

4. Specify the Join Type.

5. Specify the join type as #3.

Page 11: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 10

4. Set “Enforce Referential Integrity” 4A. Set the following Relationships

4B. Since the tblTable2 has an Orphan Record, it is unable to set the Referential Integrity. An error message appears stating it can’t complete the change.

Step 5 - Fix Table2

5A. Open the tblTable2 and delete the Orphan Record.

Step 6 - Set Referential Integrity

6A. Go to the relationships screen (Database Tools ribbon tabRelationships button). 6B. Set the Referential Integrity.

A. Select the Relationships.

A. Enforce Referential Integrity

Delete record 3.

Page 12: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 11

6C. The relationships screen should look similar to the following:

Step 7 – Test

Open the tblTable2 and add record OrderNum=3 and CustomerNum=3 You should receive the following Referential Integrity message:

Note: The Referential Integrity will not allow you to enter an Orphan Record. Conclusion Statement: Referential Integrity is a system of rules that Microsoft Access uses to ensure that relationships between records in related tables are valid. It also ensures that related data is not accidentally deleted or changed.

Step 8 – Cascade Delete 8A. Go to the Relationships Icon and set the Cascade Delete related records.

Page 13: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 12

8B. Open tblTable1 and delete record 2.

8C. The error message indicates it will delete all related records.

8D. The records in tblTable1 and tblTable2 are deleted.

Page 14: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 1 - Relational Integrity Databases

Page 13

Step 9 – Cascade Update 9A. Go to the Relationships Icon and set the Cascade Update related records.

9B. Open tblTable1 and change the CustomerNum=1 to 101. You will receive an error if Cascade Update was not set correctly.

Page 15: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 14

Chapter 2 - Advanced Database Design Data Normalization – This is a process of making a database conform to a list of standards called “Normal Forms” that help prevent problems (anomalies) and ensure the integrity of the database.

Concept Explanation / Command String in italic. Practice Exercise 9 File TabOpenDBDesign1.accdb.

Use this file to identify the concepts listed below. 2.1 Candidate Key

This is a field or group of fields that uniquely identifies a record. The difference between a Primary Key and a Candidate Key that is the Primary Key is the field that actually gets used in relationships with other tables. The Candidate Key is the “runner up” meaning it is next in line to be the Primary Key. A table can have many Candidate keys.

2.2 Non-Key Field This is a field that is not the Primary, Candidate, or part of a multi-field primary key.

Practice Exercise 10 Identify the Candidate, Primary, and Foreign keys. Customers Table

Orders Table

2.3 Dependent Field

This is a field whose value is determined by the value of another field. For example, the value in the customer’s address field is determined by the value in the customer name field. The address field is dependent on the name. All the non-key fields in a table should be dependent upon the candidate keys.

2.4 Determinant Field

This is the opposite of a dependent field, a field whose value determines the value in another field. For example, the value in the customer’s address field is determined by the value in the customer name field. The customer’s name field is a determinant. All the Primary and Candidate keys in a table should also be determinants.

2.5 Atomic

This is a value that can’t be split into smaller meaningful values. A field for an employee’s full name is not atomic. It can be split into a first name and a last name field. A street address is an atomic field. Even though you can separate the number from the street name, each part by itself has no meaningful value to the database.

Practice Exercise 11 Atomic

Determine which field can and should be split into separate fields. Non-Atomic Jack M. Johnson 125 Test Street, Dallas, TX Atomic Jack M. Johnson 125 Test Street Dallas TX

Page 16: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 2 - Advanced Database Design

Page 15

2.6 Field List Worksheet

This is a planning spreadsheet that describes the records used to create the database. The decisions you make concerning each record could have consequences later on if the design is incorrect.

Practice Exercise 12 Open Excel: File TabOpenField List.xlsx 2.7 First Normal Form

This is a rule that states that no field should be repeated in a single table. The solution then, would be to break the table up into several tables.

ContactID First Last Phone1 Phone2 123 Jed Jetson (801) 345-3435 (801) 456-0231 456 Ted York (920) 234-5634 (920) 456-2312 789 Tom Tiller (734) 234-5612 (734) 340-1201

What if you wanted to enter 3 or 4 phone numbers with this table? If isn’t possible because of table limitations.

ContactID PhID First Last PhID PhCat PNum 123 1 Jed Jetson 1 Cell (801) 345-3435 456 2 Ted York 1 Home (801) 456-0231 789 3 Tom Tiller 2 Cell (920) 234-5634 2 Bus (920) 456-2312 3 Cell (734) 234-5612 3 Off (734) 340-1201

By creating a separate table, you will be able to add multiple phone numbers for each contact. There would not be a limit to the number of phone numbers added.

2.8 Second Normal Form

This is a rule that states that all Non-Key Fields should be dependent on a single Primary Key. If there are several Primary Keys in the table, they should be broken into two tables. You would Normalize the table by mapping where the Non-Keys belong.

EmpID First Last ProjID ProjName 123 Jessy Olson 103-22 Handbook 456 Kate Peters 104-11 MailList

The non-key ProjName refers to the ProjID and the non-key First/Last names refer to the EmpID.

Employee Table Project Table EmpID EmpID

ProjectID

Page 17: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 2 - Advanced Database Design

Page 16

2.9 Third Normal Form

This is a rule that states that all Non-Key Fields in regular tables should be dependent on the Primary Key not another Non-Key Field.

JobID Desc Contact ContactPhone 123 Engineer Jed Gibbs (345) 345-2323 456 MfgAssist Deb Haze (567) 345-5678

The Contact is not a Primary Key or Candidate Key but ContactPhone is a non-key pointing to Contact. The Desc field clearly points to the Primary Key field of JobID.

Job Table Contact Table JobID JobID

ContactID

2.10 Fourth Normal Form

This is a rule that states that a table should not have multiple independent One-To-Many relationships. For example, a Customer Table may relate to the Orders table as a One-To-Many relationship. The Customer Table cannot be related to another table as a One-To-Many relationship. It can only relate to a second table as a One-To-One relationship. Customer Table Order Table

CustID Name RepID OrderID CustID Date 123 Test Co. 1 11 123 1/1/16 456 Just Co. 2 22 123 2/1/16 33 456 3/1/16

Rep Table RepID Name 1 Kit Foss 2 Kim Dessy

The Customer Table has a One-To-Many relationship with the Order Table; however, the Customer Table has a One-To-One relationship with the Rep table

SQL Database Structure – SQL uses a different relationship model to describe the database dependences.

Page 18: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 2 - Advanced Database Design

Page 17

2.11 Inner-Join Query

This is a query based on multiple tables. It shows only the records in the Left table that have corresponding records in the Right table.

This is simular to a One-To-One Relationship.

2.12 Left Outer-Join This is a query based on multiple tables. It allows you to see all the records from the Left table, and only the corresponding records from the related table on the Right.

This is similar to a Many-To-One Relationship.

2.13 Right Outer- Join

This is a query based on multiple tables. It allows you to see all the records from Right table, and only the corresponding records from the Left related table.

This is similar to a One-To-Many Relationship.

Other Topics

Page 19: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 2 - Advanced Database Design

Page 18

Common Question 1 Does every table need to have a Primary Key? Yes and No. Technically speaking, Microsoft Access will allow you to have a table with no Primary Key. However, it will also warn you, as shown below, that having a Primary Key is highly recommended

Good designers set Primary Keys in their tables because the key is required for making relationships with other tables. Referral Integrity rules require a Primary Key.

Common Question 2 Can a table have two Primary Keys? No. While a table can have multiple candidate keys, it can only have one primary key. You could have a database using two keys that make up one Primary Key. Example, last and first name together make up the Primary Key.

Common Question 3 When a table has two Candidate Keys which one should be the Primary Key? When two or more fields are “running for the office of Primary Key” you should “elect” the one that is most efficient. The most efficient field is the one that takes up the least amount of memory. For example, the CategoryID field has only two characters, while the category name field may use 10 or more characters. Two characters use less memory than ten, so you should “vote” for the CategoryID field.

Common Question 4 Does a Junction Table require a Primary Key? Yes and No. Usually, a Junction Table joins two tables that have a Many-To-Many Relationship. The Junction Table that contains fields are either Foreign or Non-Keys. A Yes answer, will allow you set both Foreign Keys in the Junction table as the Primary Key which together make up one Primary Key. A No answer, will allow you to set no Primary Key in the Junction table. Either method seems to function properly.

To view the above relationships open file DBDesign2.accdb.

Page 20: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 2 - Advanced Database Design

Page 19

Student Project B - Creating Relationships 1. File TabOpenDBDesignX.accdb. 2. Open the Relationships Window. 3. Add the Client and Project tables to the Relationships window. Note: Show Table button. 4. Create a relationship between the Client ID field in the Client table and the Client ID field

in the Project table; set referential integrity for the relationship. 5. Add the Trainer table to the Relationships window. 6. Create a relationship between the Trainer Initials field in the Project table and the Initials

field in the Trainer table; set referential integrity for the relationship.

7. Close the Relationships Window and save the changes. 8. Open the Client table in Datasheet View and view the subdatasheet for the CONCORD

client. Then, collapse the subdatasheet and close the Client table. 9. Open the Relationships Window. Delete the relationship line between the Project and

Trainer tables. Then, close the Relationships Window and save the changes. 10. Finish the relationships below:

11. Close the database file.

Page 21: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 20

Chapter 3 - Export, Import and Linking Tables In this chapter, you will learn how to Import data, Export data, and link data to an Access Table.

Concept Explanation / Command String in italic. Practice Exercise 13 File TabOpenImportExport1.accdb. 3.1 Importing Data

You can Import data from one or more external data sources. The external data source can be another Access database, a database created in a different program (such as dBASE or Excel), ASCII text, or an HTML data table.

If the external data source is an Access database, you can also Import database objects such as Queries, Reports, and Forms. This option allows you to copy a query from one database to another and modify it as necessary, rather than creating a new one. In addition, you can easily copy standard reports and forms between databases.

Practice Exercise 14 Import Data from External Source

Continue from previously opened database.

1. External Data Tab Import & Link GroupText File Datatype: Text FilesSTORENAM.TXT.

2. Inport the source data into a new table in the current database .

3. Delimited Comma. 4. First Row Contains Field Names . Let Access add primary key . Import to Table: Store Name by Rep . Open the Store Name by Rep table in Datasheet View. Then, close the table.

Page 22: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 3 - Export, Import and Linking Tables

Page 21

Practice Exercise 15 Import Excel File

Continue from previously opened database.

1. External Data Tab Import & Link GroupExcel 2. Filename: C:\Data\Access2013-2\Videosource.xlsx Import the source data into a new table in the current database.

3. Which worksheet or range would you like? Show Worksheets: CustomersNext. 4. Does the first row specified contain column headings? First row contains column headingsNext. 5. You can specify information about each of the fields you are importing. Next. 6. Choose a primary key? Choose my own primary key: Customers IDNext. 7. Import to table: CustomerFinish. 8. Import the Movies sheet using the above procedures.

Practice Exercise 16 Import Access Table

Continue from previously opened database.

1. External Data TabImport & Link GroupAccess 2. Filename: C:\Data\Access2013-2\ImportExport2.accdb. Import the source data into a new table in the current database.

3. Import ObjectsTables: Packing SlipsOk.

3.2 Exporting Data

You can Export data and database objects to a variety of supported databases, programs, and file formats. For example, you can export data to another program (such as dBASE or Excel), to ASCII text, or to an HTML data table. You can also export most database objects from a Microsoft Access database to another Access database. The process of exporting data and database objects is very similar in functionality to copying and pasting. The following table lists some of the data formats to which you can export:

Application Supported Version or Format Microsoft Access database

Access 2002, 2003, 2007, 2010, 2013, and 2016.

Microsoft Excel Excel 2003, 2007, 2010, 2013, and 2016. Microsoft Word, Rich Text Format

All

Lotus 1-2-3 wk1 and .wk3 Delimited text files All XML document All

Practice Exercise 17 Export Table

Select the Reps tableExternal Data Ribbon TabExport & Link Group

Access Double-click ImportExport2.accdb Export Reps to: Reps2

Open the ImportExport2 database. Notice that the Reps2 table appears in the Tables object list.

Page 23: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 3 - Export, Import and Linking Tables

Page 22

3.3 Export A Query Often times you may want to export Access tables to Excel Sheets, but once exported each sheet will be isolated and you not be able to link the sheets together. A query can be used to combine two tables together and export the query to Excel. Note: To link tables together in Excel, use a product called PowerPivot.

Practice Exercise 18 1. File TabOpenImportExport3.accdb. 2. Create a query: Create Ribbon TabQuery Design . 3. Show TablesCustomers and Orders. 4. Add fields Customer Number, Store, Order Number, Order Date, and Sales Reps.

5. Run and Save Query as Query1.

6. External Data Ribbon TabExport GroupExcel button File name: C:\Data\Access2013-2/Query1.xlsx. File format: Excel Workbook (*.xlsx). 7. Ok. Test: Open Excel to view the file.

3.4 Linking Data To An Access Table

You can link to an external data source, such as another Access database or a database created in a different program (Such as, Excel). The link will function like it is located in your local database. It can be useful to write Reports and Forms in a separate environment and import them to the master database when complete. A linked table displays a special icon in the Database Window. A table linked to another Access database has an arrow to the left of the icon. A table linked to a source created in a different program displays an arrow and the initials of the source program (Such as, Px for Paradox). When you delete a Linked Table, you are deleting the icon and the link to the source table, not the source table itself.

Practice Exercise 19 Link To Access Table

Continue from previously opened database.

1. External Ribbon TabAccess . 2. Browse: File Name: C:\Data\Access2013-2\ImportExport2X.accdb Link to the data source by creating a linked tableOK. 3. Tables: TrainerOK 4. The arrow indicates the table is linked to a different location:

5. Open the Trainer table in Datasheet View to view its data. 6. If you change a record, it will change the Trainer table located in the ImportExport2X.accdb database.

Page 24: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 3 - Export, Import and Linking Tables

Page 23

3.5 Linked Table Manager

Once you have linked to another table you can manage the links.

External Ribbon Tab Linked Table Manager Select the desired tableOK.

Student Project C - Using Advanced Database Features 1a. File TabOpenImportExport1X.accdb. 1b. Import the Sales by Rep 2 query from ImportExport2X.accdb. 1c. Add a link to the Sales table in ImportExport2X.accdb. 1d. Open the Linked Table Manager and update the link to the Types table in the ImportExport2x.accdb

database. Then, select OK as necessary and close the Linked Table Manager. 2a. Compact Advdatx.accdb. Then, close ImpoertExpoert1X.accdb. 3a. File TabOpenDATA2003.MDB. Convert Data2003.mdb, saving it as Data 2013.accdb. 3b. Export the Customer Addresses query to ImportExport1X.accdb; accept the default name. 3c. Close the database file.

Page 25: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 24

Chapter 4 - Operators in Queries In this chapter, you will learn how to use Comparison Operators, And conditions, Or conditions, Between AND Operator, Expression Builder, and Wildcard Character.

Concept Explanation / Command String in italic. Practice Exercise 20 File TabOpenQOperator.accdb. Use this database for the entire chapter. 4.1 Show Table

The Show Table button can be used to add needed tables to the query.

4.2 Add Fields. There are several ways to add fields to a query: 1. Double Click the field in the Table box. 2. Drag n Drop the field from the Table box. 3. Select multiple fields using the Ctrl or Shift keys.

4.3 Relationships When two tables are added, they will inherit the default relationships. The

relationships can be changed in the query and will not affect the overall relationships. However, hanging the relationships in the query may extract a different list of information.

4.4 Insert Column

To Insert a Column in the middle of several fields, select a fieldDesign Ribbon TabInsert Column .

4.5 Delete A Column

To Delete a Column: select a filedDesign Ribbon TabDelete Column .

4.6 Move A Column

To Move a Field to a different position: Select the field on the top edge and move to a different position.

4.7 Or Row The row located under the Criteria row will allow

you to perform an OR operation. This will allow you to display both Northeast and Southwest regions.

4.8 Recordset A Recordset is the result of a query after multiple criteria has been added. A Recordset in a table is the entire row of records in the datasheet.

Page 26: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 25

4.9 Using Comparison Operators

You can also add criteria to a query in order to limit the number of records in the Recordset. The simplest criteria is to find all records matching a single value. You can also use Comparison Operators to limit the Recordset to one group of records. Comparison Operators are symbols that represent conditions recognized by Access. The following Comparison Operators are available in Access: You can use one or more Comparison Operators to compare a specified value

Operator Description < less than

<= less than or equal to > greater than

>= greater than or equal to = equal to <> not equal to

Not reverses logic

to all the values in a field. When you run the query, only those records with values meeting the specified criteria appear in the Recordset.

4.10 Date Values Access automatically inserts number symbols (#) around date values. 4.11 Text Values Access automatically inserts quotation marks (" ") around alphanumeric

values. 4.12 Like String Access automatically inserts the word “Like” in front of a string when necessary.

Practice Exercise 21 Comparison Operators

Use Comparison Operators in a query to find all customers with credit limits of less than $1000. 1. Open the CSales Query in Design viewScroll as necessary and select in the Criteria row of the Credit Limit field. 2. Type <=2000 Press the Enter Key.

3. Run the query . Notice that only records with a credit limit of $2,000 or less appear in the Recordset.

Practice Exercise 22 Date Criteria

Return to Design View and delete the criterion. Find all records of customers with contract dates on or after January 1, 2002. 1. Open the CSales Query in Design viewScroll as necessary and select in the Criteria row of the Contract Date field. 2. Type >=6/1/02 Press the Enter Key.

3. Run the query . Notice that Access inserts number symbols (#) around the value to indicate a date value. Return to Design View and delete the criterion.

<=5000

Page 27: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 26

4.13 AND Operator In One Field

There may be a need to use an AND Operator in a single field for two conditions such as “CA AND UT” as shown in the next Practice Exercise.

Practice Exercise 23 And Operator In One Field

1. Open the CSales Query in Design View. 2. Select in the Criteria row of the Credit Limit field. 3. Type >=6000 and <=9000 Press the Enter Key

4. Run the query . Notice that only records that match the AND condition appear in the Recordset.

Practice Exercise 24 And Operator In One Field

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row of the Contract Date fieldType >=9/1/02 And <=9/30/02. 3. Press the Enter KeyRun

the query .Note: The Pound # sign should be added automatically.

Practice Exercise 27 OR Operator In One Field

1. Open the CSales Query in Design view and delete any previous criteria. 2. Click in the Criteria row of the State/Providence field. 3. Type PA or NY or MA or CT .

4. Press the Enter KeyRun the query . 4.14 And Condition In Two Fields

There may be a need to perform an AND operation in two fields. To do this, put the criteria in the same criteria row. This will perform an AND operation, however, the AND Operator is not needed. You may want to find all customers in PA with sales to date of under $2,000. The records must meet both conditions in order to be included in the Recordset. When two or more criteria must be met, you are creating an AND Condition. See next Practice Exercise.

Practice Exercise 25 AND Operator In Two Fields

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row of the State/Province fieldType PA. 3. Click in the Criteria row of the Sales to Date fieldType <2000.

4. Press the Enter KeyRun the query .

Page 28: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 27

Practice Exercise 26 And Condition

Find all records of customers with contract dates on or after 1/1/02 and sales to date of $4,000 or more. 1. Return to Design View and delete the criteria. 2. Contract Date field first Criteria row Type >=1/1/02 3. Sales to Date field first Criteria row Type >=4000

4. Run the query . Notice that only records that match both AND conditions appear in the Recordset. Return to Design View and delete the criteria.

4.15 OR Condition There may be a need to perform an OR Operation in one field. This is another

way to use an OR Operator in a single field. To do this, put the criteria in different criteria rows. You may want to find several regions such as Northwest or Southwest. Both records must meet the conditions in order to be included in the Recordset. See next Practice Exercise.

Practice Exercise 28 OR Condition Single Field

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row 1 of the Region field Type Northwest. 3. Click in the Criteria row 2 of the Region field Type Southwest.

4. Press the Enter KeyRun the query .

Practice Exercise 29 OR Condition Two Fields

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row 1 of the Region fieldType Southwest 3. Click in the Criteria row 2 of the Customer Type fieldType 3

4. Press the Enter KeyRun the query . Notice the result shows other regions containing the Customer Type or 3. Criteria Design View Result Datasheet View

Page 29: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 28

Practice Exercise 30 OR Condition Two Fields

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row 1 of the Contract Dates fieldType <=1/1/2003. 3. Click in the Criteria row 2 of the Credit Limits fieldType >3000.

4. Press the Enter KeyRun the query . Notice: The result shows approximately 40 records. Criteria Design View Result Datasheet View

4.16 And / Or You can create additional OR/AND Conditions by typing criteria into the Criteria row, Or row, or any row below the Or row. Any criteria entered into the same Criteria row creates an AND condition, any criteria entered into different rows creates an OR condition. You can even create a combination of AND and OR Conditions.

Practice Exercise 31 1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row 1 of the Sales to Date fieldType >2000. 3. Click in the Criteria row 1 of the Region fieldType Northeast. 4. Click in the Criteria row 2 of the State/Province fieldType PA.

5. Press the Enter KeyRun the query . Criteria Design View Result Datasheet View

4.17 Between And Operator

You can use the Between AND Operator to find data that includes or falls between two stated values. To find all records of customers with credit limits between 1000 and 2000, for example, you would enter Between 1000 And 2000 in the Criteria row of the Credit Limit field. The Between AND Operator can be used in text, numeric, date fields, and the actual value (1000 and 2000) in the criteria will be included in the Recordset.

Practice Exercise 32 Between And operator

1. Open the “CSales Query” in Design View and delete any previous criteria. 2. Click in the Criteria row of the Credit Limit field Type between 1000 and 2000

3. Press the Enter KeyRun the query . Notice that only records matching the criteria appear in the Recordset. Criteria Design View Result Datasheet View

Page 30: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 29

4.18 Expression Builder

The Expression Builder is a tool that provides all the elements needed to build the expression. You can type in the criteria or use the Expression Builder. Expressions are calculations and can include database objects, operators, and values. Objects range from table fields to controls in a form. Operators are standard mathematical operators used in calculations (such as +, -, *, /, (), <>). Values can be numbers, dates, text, and built-in functions, as well as field, control, and property identifiers. The Following is an example of the Expression Builder. You can use a combination of typing values or use the elements in the Expression Builder. Also, the Undo (Ctrl Z) command will work for one undo operation. Be careful to single-click when expanding a subcategory; double-clicking a subcategory inserts the first subcategory value.

Practice Exercise 33 Expression Builder

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row of the Contract Date fieldRight-Click OperatorsComparisonDouble-click Between in the right pane. 3. Double-click the first <Expr> Type 6/1/01 4. Double-click the second <Expr> Type 6/1/2002

5. Run the query . Notice that only records matching the criteria appear in the Recordset. Criteria Design View Result Datasheet View

Page 31: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 30

4.19 Wildcard Character

You can use a Wildcard in a query in place of one or several characters. Wildcard characters are helpful when you want to find criteria with a pattern (such as all last names beginning with M), or if you are not sure exactly how the values you want to find will appear (such as the correct spelling—Kline or Klein). The two most common Wildcards are listed in the following table:

Wildcard Used for Example ? Any single letter

or number Sm?th finds Smith and Smyth, whereas ?andy finds Sandy, Randy, etc.

* One or more letters or numbers

M* finds all records that start with M; 8/*/00 finds all dates in August, 2000; and *ball* finds all records that have the text ball anywhere in the field

Wildcards are not case-sensitive (for example, *ill finds Bill and bill). When you use wildcard characters (? and *), Access automatically inserts the word Like before the criteria and quotation marks (" ") around the text.

Practice Exercise 34 Wildcard Character

1. Open the CSales Query in Design View and delete any previous criteria. 2. Click in the Criteria row of the Store Name fieldType sport* Press Enter Key.

3. Run the query . Notice that only records matching the criteria appear in the Recordset. Criteria Design View Result Datasheet View

4.20 Is Not Null Records can be suppressed if they contain no data. The Is Not Null operator will suppress a record if a specific field contains not data.

Practice Exercise 35 1. Create new query: Create Ribbon TabQuery Design Show TablesOrders. 2. Add fields: Order Number, Order Date and Notes. 3. In the Notes Criteria enter: Is Not Null. 4. Test the query (without the Is Not Null all records will be displayed).

Page 32: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 4 - Operators in Queries

Page 31

Student Project D - Using Operators in Queries

1. File TabOpenQOperatorX.accdb. 2. Open the Course Query in Design View. 3. Set criteria to find only projects with a cost of more than $150. (Hint: Try using the > operator.) 4. Use Wildcards and an Or Condition to find only records with the text excel or word occurring

anywhere in the course name. (Hint: Use asterisks both before and after each criterion.) 5. Use the Expression Builder to find only records with a start date between 4/1/2003 and

6/30/2003. Query in Design View

Query in Designsheet View

6. Remove all criteria above. 7. Find all records with trainer initials of DF and a cost of $175 or more.

7. Close the query and close the database file.

Page 33: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 32

Chapter 5 - Advanced Queries In this chapter, you will learn how to set Top Values in a query, create a Calculated Field, format a Calculated Field, display a Totals Row in a query, create a Function Query, create a Parameter Query, use Multivalued Fields, create a Concatenation in a query, and Filter a query.

Concept Explanation / Command String in italic. Practice Exercise 36 File TabOpenQAdvanced.accdb. Use this database for the entire chapter. 5.1 Sort Change the Sort order by selecting the Sort

row. Choose either Ascending or Descending options. To Sort multiple columns, the left most field will be sorted first. If you want to sort by a specific field and place the field at the end of the list, you will need to place

the field twice and disable the first sort field. In the example below, the show button is turned off, but sorted first, and the viewable field is placed third.

5.2 Show Check Box

Check this if you want to Hide the field from the final results. This can be used to Show/Hide important information for testing purposes only if you do not want to see the field in the final results.

5.3 SQL View To show the SQL code: View dropdown SQL View.

Query Techniques

5.4 Top Values In A Query

You can limit the results of a query so that only the highest or lowest values in a field appear in the Recordset. For example, you can set the return of a Quantity Sold field to 10 to find the top ten best-selling products. You can also limit the number of records to a specific number or percentage of all records being queried (such as, the top 25%). The field for which you are setting the top or bottom values, must be sorted. If the field is sorted in descending order (Z to A, 9 to 0), the top values will be found. If the field is sorted in ascending order (A to Z, 0 to 9), the bottom values will be found.

If other fields in the query are sorted, they must appear to the right of the field for which you are finding top or bottom values in the design grid. You can also type a value into the Return box on the Design Ribbon Tab.

Practice Exercise 37 Set Top Values

1. Open the CSales Query in Design View Scroll as necessary and click in the Sort row of the Sales to Date field. 2. Sort Dropdown Decending.

3. Design Ribbon TabReturn 5

.

4. Run the query . If necessary, scroll to view the Sales to Date field. Notice that the top five sales to date are listed in descending order.

Page 34: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 33

Criteria Design View Return Dropdown Result Datasheet View

Return to Design View. Set the top values back to All and remove the sort from the Sales to Date field. Then, close the query, saving the changes.

5.5 Calculated Field

A Calculated Field query allows you to create Expressions that calculate new field values; for example, you can create an expression that multiplies the value in the Quantity field by the value in the Price field to calculate total sales. Field names from the table are enclosed in square brackets ([ ]) and the colon separates the column name from the expression such as Commission: 2*[Sales]. You can also use the Expression Builder to create a Calculated Field by selecting any blank Field row and selecting the Builder button on the Design Ribbon Tab.

Practice Exercise 38 Calculated Field

1. Open the Reps Pay Query in Design ViewClick in the Field row to the right of Commission Rate. 2. Type Commission: [ord tot]* [commission rate] Press the Enter Key.

3. Run the query . Criteria Design View Result Datasheet View

Notice that the Commission Field displays the results of the value in the Ord Tot field multiplied by the percentage in the Commission Rate field. Save the query and switch back to Design View.

5.6 Calculated Field From A Calculated Field

This happens when you nest a Calculated Field from another Calculated Field. You must check the Show check box in order to execute the field and use its results in a second field. In the example below, in column 2, it will create the calculated field AdjCredit and in column 3, the AdjCredit is used in the formula:

Results of the above query:

If the Show is unchecked in column 2 the query will not function properly:

Page 35: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 34

5.7 Formatting A Calculated Field

Once you have created a calculated field, you can change its properties as you would any other field on the design grid. The Format property determines how data appears in Datasheet View. For example, you can change the properties of a calculated field so that the field values display as currency. You can also change the format of a calculated field by right-clicking anywhere in it and selecting Properties.

Practice Exercise 39 Format

1. Open the Reps Pay Query in Design View. 2. Scroll as necessary and click anywhere in the Commission:[ord tot]*[commission rate] field 3. Design Ribbon Tab General tabFormat

PropertyFormat Dropdown Currency.

4. Run the Query and notice that the Commission Field is now formatted as currency.

5.8 Totals Row Query

The Totals Row Query feature allows you to create groups based on a selected field and then apply a function that calculates a value within the grouped fields. For example, you could group records by state and then select the Count Function to find out how many customers (records) are in each state (field); or, you could group records by customer name and then calculate the Sum of each customer’s orders. There are several types of functions from which you can choose: Function Description Sum Calculates the total of each “Group By” field. Avg Calculates the average of each “Group By” field. Count Calculates the number of values in each “Group By” field, not

counting Null (blank) values. Min Displays the Lowest value in each “Group By” field. Max Displays the Highest value in each “Group By” field. StDev Calculates the Standard Deviation (Calculates the values located in

the middle/mean average and drops the unusual high/low values) of each “Group By” field.

First Displays the First value in each “Group By” field. Last Displays the Last value in each “Group By” field. To perform more than one calculation on a field, you must add the field to the design grid a second time, and create the desired expression.

Page 36: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 35

5.9 Totals Row Advanced

Expression This calculates a Mathematical Expression located in the Criteria row in each “Group By” field. Example: You can place any function such as “Sum” in the Criteria.

Where This performs a Where clause in the criteria row. Where Example1: This can be used to fine tune the results to a specific region rather than all regions. Query Design View: Results:

Where Example2: If using numeric criteria (such as ” >5000”), it will only display the states that fulfill the criteria. Query Design View: Results:

Practice Exercise 40 Function Query

1. Open the Region Totals query in Design ViewClick on any field.

2. Design Ribbon TabTotals . 3. Click in the Sales to Date field Totals row.

4. Sum Run the query . Criteria Design View Result Datasheet View

Notice that a Sales to Date field appears for each customer in the region. This is because the Region is Grouped By in the Total Row. 5. Switch back to the Design ViewChange the function to Avg in the Sales to Date field.

Page 37: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 36

5.10 Parameter Query

You can create a query to which you add different criteria each time you run it; such a query is called a Parameter Query. This is designed to prompt the user for input each time it is run; Access then runs the query based on the criterion (parameter) entered. A Parameter Query allows you to quickly and easily change query criteria without having to redesign the query.

You can add multiple parameters to a query; when you run to, a prompt will appear for each parameter in it.

Practice Exercise 41 Parameter Query

1. Open the Customer Addresses query in Design View. 2. Scroll as necessary and click in the Criteria row of the Region field

Type [Enter the Region:] Press the Enter Key.

3. Run the Parameter Query . At the prompt, type Northeast and select . Notice that only records matching the criteria appear in the Recordset. 4. Test the Parameter Query again by typing: Southwest.

5.11 Multivalued Fields

When using a Multivalued Field in a query, you can choose whether to retrieve the entire Multivalued Field containing all the values separated by commas, or a separate row for each value.

Practice Exercise 42 Multivalued Fields

1. Create A form: Select Items2 tableCreate Ribbon TabForm Button. 2. ViewForm View. 3. Review the combo boxes on Product Description and Color fields. Note: You cannot use a Combo Box control to create a Multivalue Field. The Multivalued Field must be created at the Table level using a Lookup Wizard. At the end of the Lookup Wizard, check the option . At the Form level in the Design View, Choose Design Ribbon TabAdd existing fields

. The Combo Box automatically creates the field in the Form.

Page 38: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 37

5.12 Concatenation In A Query

A Concatenation Query allows you to combine two or more text fields into one field. In other words, Concatenation enables you to append one text string to another. In addition, you can insert characters between the text strings as needed. For example, you can concatenate the City, State, and Postal Code fields and store the concatenated text string in a fourth field, the Address field, adding commas and spaces between the text strings as needed.

When typing a Concatenation Expression, the first part of the expression defines the name of the new field and the second part of the expression defines the fields which are to be concatenated. All field names must be surrounded by brackets. The Concatenation Character (the ampersand - &) appears between field names, and you must enclose any additional characters in double quotes. For example, the expression Names: [Last Name]&", "&[First Name] concatenates the Last Name and First Name fields and inserts the concatenated text string into a field called Names. The new field displays the last name, a comma, a space, and the first name for each record in the table.

Practice Exercise 43 Concatenation

Query

1. Open the Rep Orders query in Design ViewClick in the blank Field row to the right of Customer ID 2. Type Sales Rep: [first_name]&" "& [last_name] Press the Enter key.

3. Run the query . Widen the Sales Rep column as necessary to display all the characters in it. Notice that the Sales Rep column displays the first and last name, separated by a space.

5.13 Filtering A Query

You can Filter A Query in the same way you filter a table or form. Since the data you want to filter sometimes appears in two or more tables, you might need to create a multiple table query. Once the query has been created, you can apply a filter to temporarily isolate the records you want to view. The Filter By Selection feature allows you to quickly and easily filter a query to display only those records in which the selected value appears. Conversely, the Filter Excluding Selection feature filters out the selected value, leaving only those records that do not contain the selected value. The Filter By Form feature allows you to create more complex filters by filtering on multiple values and/or by creating filter expressions. In the Filter by Form window, for example, you can create AND and OR Filters, use Wildcards, and Filter by Ranges.

Page 39: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 38

Practice Exercise 44 Filter A Query

1. Open the Store Shipping Dates 2 query in Datasheet ViewClick in the field containing the text Athletic Supplies Co. 2. Home Ribbon TabFilter button Text FiltersEquals Custom Filter: Athletic Supplies Co.

Remove the filter by selecting the Toggle Filter button on the Home Ribbon Tab.

Student Project E - Designing Advanced Queries

1. File TabOpenQAdvancedX.accdb.

2a. Open the Project Sales query in Design View and run the query after each design. 2b. Create a new calculated field named Total Sales that multiplies the number of students to be

trained (Students field in the Project table) by the per student cost of the course (Cost field in the Courses table). (Hint: Use the format Total Sales:[students]*[cost].)

Design View Datasheet View

3a. Open the Trainer Pay query in Design View.(Hint: Right Click and select Design View 3b. Create a new field that concatenates the first and last names of each trainer. Name the field Trainer

Name and use the Last Name, First Name format. (Hint: Use the format Trainer Name:[last name]&", "&[first name].)

3c. Trainers are paid fifteen percent of the total sale for each project. Create a calculated field named Pay that calculates the trainer's pay for each project. (Hint: Use the format Pay:[students]*[cost]*.15.)

3d. Format the Pay field as currency. 3e. Find the three trainers with the highest pay. (Hint: Sort the Pay field in Descending order and type

3 into the Return box on the toolbar.)

Set Return to 3 Design View Datasheet View

Page 40: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 5 - Advanced Queries

Page 39

4. Reset the Pay field back to (not sorted) and the top values back to All; then, add the Total row to sum the total for each instructor. (Hint: Use the Totals button on the Query Design toolbar.)

Design View Datasheet View

5. Use the Filter by Selection button to display only those records for George Edwards. Selection Datasheet View

6a. Open the Sales by Rep query in Design View. Add a parameter to the Criteria row of the Sales

Rep field that prompts you to enter the initials of the sales representative each time the query is run. (Hint: Remember to use both opening and closing brackets.)

6b. Run the query , typing sh when prompted. Notice that only records that match the criteria appear in the Recordset.

Design View Parameter

7. Close the query and close the database file.

Page 41: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 40

Chapter 6 - Action, Crosstab, And Duplicate Queries In this chapter, you will learn how to create a Make-Table Query, Update Query, Append Query, Delete Query, use the Crosstab Query Wizard, the Find Duplicates Query Wizard, and use the Find Unmatched Query Wizard.

Concept Explanation / Command String in italic. Practice Exercise 45 File TabOpenQWizard1.accdb. 6.1 Action Queries Action Queries can be dangerous by updating or deleting records in a database. It

is suggested that you make a copy of the Database and develop the action query on the backup. When it is working properly, you can import the action query into the main database. Once you update or delete records there is no way to undo the operation.

6.2 Make Table Query

A Make Table Query creates a new table from data in existing tables and queries. Make Table Queries have many uses. The new table can be a duplicate of an existing table to serve as a data backup. You can then delete old records from the original table, for example, leaving them stored in the backup table. Make Table Queries can create a compact version of an existing table, displaying only those fields you want to see. They can also bring fields from many tables into one table, making reports and queries based on the new, single table that will run faster. You can limit both records and fields in a new table. If you use criteria in a Make Table Query, only those records that meet the criteria will be added to the new table.

Note: A Make Table Query can be used to create a Lookup Table. Example: tddReps table.

The fields in the new table retain the data type and field size properties assigned to them in the source tables.

Page 42: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 41

Practice Exercise 46 Make Table Query

1. Create Ribbon TabQuery Design Customers TableClose. 2. Add the Region field to the query 3. Make sure you go to Properties of the query (Right-Click in the gray area of the query on the top section.) and set Unique values to yes.

4. Test out the query to see if it produces the desired results.

5. Change it to a Make Table Query: View Design View .

6. Design Ribbon TabMake Table Query Table Name: tddRegion

7. Run the query .

8. Save the query as: qmtRegion. Additional Exercises: 9. Create a query using the Country table. Make a unique table and call it tddCountry, then save the query as qmtCountry. 10. Create a query using the State/Province table. Make a unique table and call it tddState/Province, then save the query as qmtState/Province.

Page 43: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 42

6.3 Update Query

An Update Query is used to change data values in an existing table. Update Queries save time because they allow you to update a large number of records at one time. You can use an update query, for example, to increase all the values in a Unit Price field by 10%. You can also use an Update Query to calculate and enter values in a table field. You could, for example, use an update query to multiply the value in the Unit Price field by 75% and place the result of the calculation in the Sale Price field of the same record. If you do not want to update all the records in the table, you can use criteria to select only those records you want to update. For example, you can add criteria to an Update Query to increase the unit price on only one product line, rather than on all products. Not all table fields have to be included in an Update Query. You need to include only those fields you want to update and those to which you want to add criteria. When you use field names in any expression, they must be enclosed in square brackets ([ ]). An Update Query permanently alters field values; make sure that the correct records are selected and that the expression in the Update To row of the design grid is correct.

Practice Exercise 47 Update Query

1. Create Ribbon TabQuery Design Customers TableClose. 2. Add the Region field to the query. 3. Add criteria of Southeast. 4. Add a calculated field value to multiply the credit Limit by 10% in the blank column. Type in the following in the blank Field row: Adj: [Credit Limit] * 1.1.

5. Test out the query to see if it produces the desired results. 6. Delete the calculation field and add the credit limit field. 7. Change it to an Update Query and add [Credit Limit] * 1.1 to the “Update To:” Row. Note: Customer 1014 has a credit limit of 8000 prior to the update query. After you run the query the value will be 8800.

8. Run the update query .

9. Save the update query as qupCreditLimit. 10. Verify the customer record 1014 the Credit Limit field to see if it updated the

Northeast Credit Limit by 10%. If you run the query a second time, it will update again.

Page 44: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 43

6.4 Delete Query

You can use a Delete Query to maintain the appearance, usefulness, and efficiency of tables in a database. When records have been appended or archived to a secondary table, or they are simply no longer of use to you, it is a good idea to delete them. Deleting records saves disk space and makes tables more efficient; the more data there is in a table, the more time it takes to save, sort, and query a table. Delete Queries enable you to apply criteria to select and delete groups of records at one time. A Delete Query always deletes entire records; you cannot use one to delete data only in specific fields. The records deleted by a delete query are not retrievable. Therefore, you should always preview the selected records by first running a select query. Only after you have confirmed that the selected records are correct should you run the delete query.

Practice Exercise 48 Delete Table Query 1. Create Ribbon TabQuery Design Customers TableClose.

2. Add all records to the query. 3. Add the criteria of Northeast to the Region criteria.

4. Test out the query to see if it produces the desired results.

5. Change it to a Delete Table Query: View Design View Delete

Table Query

6. Run the query .

7. Save the query as: qdlNortheast. Verify if the Northeast region was deleted in the Customers Table.

6.5 Append Query An Append Query copies records from one table or query and adds them to the end of a different table. Append Queries are useful in transferring data from one table to another. You can also use an Append Query to archive some or all table data. If you have two tables, Current Orders and Old Orders, for example, you can use an Append Query to copy records from the Current Orders table and add them to the Old Orders table. This eliminates the need to manually type the records into the Old Orders table. If the fields in both tables have the same names, the copied data is automatically appended. If the fields have different names, however, you must specify the fields to which you want to append the data. You can use criteria to select the records you want to append. Only those records that meet the criteria are appended to the table.

Page 45: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 44

Practice Exercise 49 Append Query

1. Open the tblNortheast table to view the region field and close the table.

2. Create Ribbon TabQuery Design Add tblNortheast TableClose. 3. Add all records to the query (use the shift key to select all records).

4. Test out the query to see if it produces the desired results. 5. Change it to an Append Query and Enter name Customers .

6. Run the query .

7. Open the Customers Table to verify that the records were appended to the table.

Crosstab, Duplicate, and Unmatched Query

Practice Exercise 50 File TabOpenQWizard2.accdb. 6.6 Crosstab Query Wizard

Crosstab Queries are used to group and summarize information in a spreadsheet format similar to a PivotTable. Crosstab Queries make it easier to read and analyze selected data. The Crosstab Query Wizard provides a step by step process to help you quickly create a Crosstab Query, allowing you to enter information about the tables and fields you want to add to your query. You must have three fields in a Crosstab Query. The values in the first field appear as row headings in the resultant spreadsheet, the values in the second field appear as column headings, and the calculation is performed on the values in the third field.

Page 46: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 45

Practice Exercise 51 Crosstab Query

1. Create Ribbon TabQuery Wizard Crosstab Query Wizard . 2. Which table or query contains the fields you want for the crosstab query results? Table: Packing Slip . 3. Which fields’ values do you want as row headings? Double-click Prod ID . 4. Which fields’ values do you want as column headings? Sales Rep . 5. What number do you want calculated for each column and row intersection? QtySum . 6. What do you want to name your query? Type Product Sales by Rep .

6.7 Find Duplicates Query Wizard

You can use the Find Duplicates Query Wizard to find duplicate records in a table. For instance, there may be identical records stored in a table, when only one record is necessary. The Find Duplicates Query Wizard will find the duplicate records so that you can delete them from the table.

Practice Exercise 52 1. Create Ribbon TabQuery Wizard Find Duplicates Query Wizard

. 2. Which table or query do you want to search for duplicate field values? Table: Customers . 3. Which fields might contain duplicate field values? Double-click Store Name . 4. Do you want the query to show fields in addition to those with duplicate values? Add the following fields to the query: Customer Number, Contact Name, and Phone Number 5. What do you want to name your query? Type Duplicate Customers . Notice that four records appear in the Recordset; there are several duplicate records in the Customers Table.

6.8 Find Unmatched Query Wizard

The Find Unmatched Query Wizard helps you manage data in related tables and can be used to find orphan records that do not have a relationship to other tables. This wizard finds records that are “orphans,” meaning that they have no corresponding records in the related table. Suppose, for example, that you have deleted the records of inactive customers from a Customers Table. Two years later, one of those customers places an order, which is entered into the Orders Table. Because the Customers and Orders Tables are related, however, having an order without the corresponding customer data will cause problems. You can use the Find Unmatched Query Wizard to correct the problem by updating the Customers table. Note: Unmatched records cannot occur if Referential Integrity is enforced in the table relationship.

Page 47: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 46

Practice Exercise 53 Unmatched Records

1. Create Ribbon TabQuery Wizard Find Unmatched Query Wizard . 2. Which table or query contains records you want in the query results? Table: Orders . 3. Which table or query contains the related records? Table: Customers . 4. What piece of information is in both tables? Customer IDCustomer NumberSelect .

5. What fields do you want to see in the query results? Add the following fields to the query: Customer ID, Order Number, and Order Date . 6. What do you want to name your query? Type Unmatched Orders . Note: If you were running this query in a working or live database, the records that appear would need to be corrected to ensure database integrity.

Student Project F - Creating Action Queries, Cross Tab, Duplicate and Unmatched Queries

1. File TabOpenQWizard1X.accdb. 2a. Create a query in Design View. Add the Client, Courses, and Project Tables. Also add the

Client Balance Due query. 2b. Add the following fields to the design grid in the order listed:

Table/Query Field Client Client Name Client Address Client City Client State Client Zip Courses Course Name Client Balance Due Balance Due

2c. Enter criteria in the Balance Due Field to select only those records with an outstanding balance (Hint: >0) and text the query.

Make Table Query 3a. Create a Make Table Query. Name the table Invoice. Then, run the Make Table Query,

selecting at the prompt. 3b. Close the Make Table Query, saving it as Create Invoice.

Page 48: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 47

3c. Open the Invoice Table in Datasheet View. Notice that the table contains all the information you need to send an invoice. Then, close the Invoice Table.

Update Query 4a. Create a query in Design View. Add the Invoice Table and then add the Balance Due Field to

the design grid. Test the query using in a calculation field: [Balance Due]*1.05. 4b. Create an Update Query. Then use the Update To Row to increase the values in the Balance

Due Field by five percent. (Hint: Try using [Balance Due]*1.05.) Run the query , selecting at the prompt.

4c. Close the update query, saving it as Surcharge. 4c. Open the Invoice Table in Datasheet View. Notice that the Balance Due Field has been

updated. Then, close the Invoice Table.

Append Query 5a. Create a Query Design and add the Interviews Table, and then add each field to the design grid

in the same order as in the table. Run the query and scroll to view the Hire? Field. Then, return to Design View.

5b. Have the query select only those records that have the Hire? Field check box selected. (Hint:

Use a criteria of true.) Run the query to view the results. Then, return to Design View. 5c. Create an Append Query to the Trainer Table. Then, run the Append Query. Select

to append the records. 5d. Close the Append Query, saving it as New Trainers.

Query Criteria

Append the Query to

Page 49: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 48

Delete Query 6a. Open the Trainer Table in Datasheet View to verify that the new records were added. Then,

close the Trainer Table. 6b. Create a new query to remove all the newly hired trainers from the Interviews Table since they

are now listed in the Trainer Table. Add only the Interviews Table to the query and then add only the Hire? Field to the design grid.

6c. Add a criterion of true to the Hire? Field. Create a delete query. Then, run the query , selecting the prompt.

6d. Close the delete query, saving it as Delete Hires. 6e. Open the Interviews Table in Datasheet View to verify that the records were deleted. Then,

close the Interviews Table. 6f. Close the database file.

Crosstab Query 7a. File TabOpenQWizard2X.accdb. 7b. Create a Crosstab Query from the existing Sales by Rep query. Use the Client ID Field for the

row headings and the Sales Rep Field for the column headings. Have the calculated value be the sum of the Total Sales Field.

7c. Name the query Total Sales by Sales Rep, and select the option to view the query. After you have viewed the Recordset, close the query.

Find Duplicates Query Wizard 8a. Use the Find Duplicates Query Wizard to locate any duplicate records in the Client Table.

Select the Client Name, Address, and City Fields as possible duplicate-value fields. Do not select any additional fields to display in the query.

8b. Name the query Find Duplicate Clients and select the option to view the query. Notice that two duplicate records were found. Close the query.

Page 50: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 6 - Actions, Crosstabs, and Duplicate Queries

Page 49

Find Unmatched Query Wizard 9a. Use the Find Unmatched Query Wizard to find any projects in the Project Table that have no

record of payment in the Payment Table. Select the Project ID Field as the matching field for the two tables, if necessary. Then, have the Client ID, Course Name, and End Date Fields also be displayed in the query.

9b. Name the query No Record of Payment and select the option to view the results. After you have viewed the Recordset, close the query.

9c. Close the database file.

Page 51: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 50

Chapter 7 - Form and Report Design In this chapter, you will learn how to use Controls, Control Layouts, Stacked Layout, Tabular Layout, remove a control from a Layout, Move Controls, view the properties of an object, change a Control Property, select Non-Adjacent Controls, select Adjacent Controls, Delete Controls, size a control by dragging, size controls automatically, set Control Margins, set control Padding, hide the Ruler, disable the Snap to Grid Feature, display the Field List, add a field, add a field from another table, move part of a Paired Control, Align controls, and Space controls.

Concept Explanation / Command String in italic. Practice Exercise 54 1. File TabOpen Layout1.accdb.

Use this database for the entire chapter. 2. Create Ribbon TabForm Wizard 3. Which Fields do you want on your form? Table: Reps. Selected Fields: Add all fields . 4. What layout would you like for your form? The four layouts are documented and displayed below:

7.1 Columar Layout Columar Layouts are good for forms but not for Reports.

7.2 Tabular Layout

Tabular Layouts controls are arranged like a spreadsheet in columns and rows, with labels at the top.

7.3 Datasheet Layout

The Datasheet Layout looks exactly like a Spreadsheet.

Page 52: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 51

7.4 Justified Layout

The Justified Layout creates a navigation tool under the form.

7.5 Stacked Layout In Stacked Layouts, controls are arranged vertically, with the label to the left of

each control. Access automatically creates Stacked Layouts when you create a new form by using the Form Button, or the Blank form Button.

Practice Exercise 55

Stacked Layout

Open the Customer Data Entry form in Design ViewDraw a box around all form fields to select them.

Right-ClickLayout Stacked Close the form without saving. 7.6 Removing Layout

You can remove one or more controls from a layout and place them anywhere on the form without affecting the position of the other controls.

Practice Exercise 56 Remove Layout

1. Try to move the Initials field or label out of the group. 2. Select Reps Table on the left sideCreate ribbon tabForm button. 3. View dropdownDesign View. 4. Right-Click on Initials fieldLayoutRemove Layout. Notice that you can now move the controls individually.

Page 53: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 52

Controls

7.7 Controls

When you create forms or reports in Design View, controls are used. Controls are objects in a form or report that contain information. Forms and Reports usually include bound text box controls and unbound label controls. Bound Text Box Controls display data from fields in a table or query on which a form or report is based. Text boxes are also used as entry fields for data in a form. Text boxes are known as bound controls because the source of the data is stored in a specific field in a table. Labels are Unbound Controls. They display information that is not stored in a table. Unbound Controls can be text, images, lines, or rectangles drawn on the design and are often paired with bound controls as labels. Unbound Controls are also used to enhance a form or report, or to provide more information, such as instructions for entering data.

7.8 Moving Controls

You can move a Paired Bound and Unbound Control (such as, a field text box and its label) as a single unit to any location in a form or report in Design View. When you move one control in a pair, its corresponding control automatically moves along with it. When you select on the control handle , located in the upper left corner, both Bound and Unbound Controls will move together as a single unit. The arrow keys can be used to move the controls once selected. Holding the Ctrl Key while dragging temporarily suspends the Snap to Grid feature and allows you to freely position a control. To move a control while keeping it in the same horizontal or vertical position, hold the Shift Key and select the control. Then drag the control by its move handle either horizontally or vertically. The first direction you drag determines which position will be maintained.

Practice Exercise 57 Move Selected Controls

1. Open the Customer Sales 3 form in Design View. 2. Drag/draw a box to select the Sales to Date and Sales Rep label (include their text boxes). 3. Use the Shift and Ctrl keys to move the other fields.

7.9 Non-Adjacent Controls

Controls are the building blocks of a form or report. In order to make any changes to an element of a form or report, you must select the control that defines the element. When a control is selected in Design View, sizing handles appear. Sizing handles are boxes on the corners and sides of the control. The large box that

appears in the upper left corner of a control is a Move Handle. Move handles are used to move an individual control without moving any other controls, even if they are selected.

Control Handle.

Page 54: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 53

Practice Exercise 58 Non-Adjacent Controls

1. Open the Customer Sales form in Design ViewClick the Contract Date text

box (bound control) . 2. Hold the Shift Key and click the Customer Type text box. 3. Notice the sizing handles that appear around the bound controls (text boxes). 4. Notice that a moving handle also appears in the upper left corner of both the bound (text box) and unbound (label) controls.

7.10 Moving Part Of A Paired Control

A Bound and an Unbound Control can be Paired (linked together). When you select a Bound Control, the Unbound Control is selected. An example is a field text box (the Bound Control) and its label (the Unbound Control). You can reposition these controls as a single unit, or you can reposition them individually.

Practice Exercise 59

Paired Control

1. Open the Customer 2 form in Design View 2. Click the Note labelPoint to the large sizing handle in the upper left corner of the Note labelDrag the Note label and center it under the Credit Limit labelNow move the Notes field and size it larger.

7.11 Deleting Controls

You can Delete Controls from Design View. You can also Undo the operation, but you cannot restore a deleted control after you have saved the form or report design.

Practice Exercise 60 Delete Controls

1. Open the Customer Sales form in Design View. 2. Click the Customer Type text boxPress the Delete Key.

7.12 Sizing A Control

You can change the Size of any control in Design View by selecting the round dot

on the left or right side of the text box. . Practice Exercise 61 Size A Control

1. Open the Customer Sales 2 form in Design View. 2. Click the Sales to Date text boxPoint to the sizing handle in the middle of the right edge of the Sales to Date text boxDrag until the box is larger.

Page 55: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 54

7.13 Sizing Controls Automatically

The Arrange Ribbon Tab has formatting buttons that can be selected to size controls automatically. You can use these buttons to improve the appearance of a form or report by giving the display a consistent and orderly look. Available sizing options are listed in the following table:

Option Description To Fit Sizes the controls to fit the contents. To Grid Sizes the controls to the grid. To Tallest All selected controls become as tall as the tallest control

in the selection. To Shortest All selected controls become as short as the shortest

control in the selection. To Widest All selected controls become as wide as the widest

control in the selection. To Narrowest All selected controls become as narrow as the narrowest

control in the selection.

Practice Exercise 62

Automatic Size Controls

1. Open the Customer Sales 3 form in Design View. 2. Drag to select all the controls

Arrange Ribbon TabSize and Space WidestClick in a blank area of the form to deselect the controlsSwitch to Form View to see the results.

Arrange Ribbon Tab

7.14 Control Margins

You can use the Control Margins button in the Control Layout Group on the Arrange Ribbon Tab to specify the location of information displayed within a control. There are four options to choose from: None, Narrow, Medium, and Wide.

Practice Exercise 63 Control Margins

1. Open the Customer Data Entry 2 form in Design View. 2. Drag to select all the controlsArrange Ribbon TabControl Margins

MediumControl Margins Narrow. 7.15 Control Padding

You can use the Control Padding button in the Control Layout Group on the Arrange Ribbon Tab to set the amount of spacing between controls and the gridlines of a layout. There are four options to choose from: None, Narrow, Medium, and Wide.

Practice Exercise 64 Control Padding

1. Open the Customer Data Entry 2 form in Design View. 2. Drag to select all the controlsArrange Ribbon Tab Control Padding

WideControl Padding Medium.

Page 56: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 55

7.16 Aligning Controls

You can automatically Align Controls with one another. This option allows you to line up the edges of controls more quickly and accurately than lining them up individually. The available alignment options are listed in the following table:

Option Description Left The left edges of the controls are aligned with the left edge of the

leftmost control in the selection. Right The right edges of the controls are aligned with the right edge of

the rightmost control in the selection. Top The top edges of the controls are aligned with the top edge of the

top control in the selection. Bottom The bottom edges of the controls are aligned with the bottom edge

of the bottom control in the selection. To Grid The controls are aligned with the grid.

Practice Exercise 65 Align Controls

1. Open the Customer 3 form in Design View. 2. Hold the Shift Key and click the Customer Number, Store Name, Region, Credit Limit, and Note text boxesArrange Ribbon TabAlign Click in a blank area of the form to deselect the controls.

7.17 Spacing Controls

You can increase or decrease the spacing between selected controls, or space them evenly between the top and bottom controls. You can also implement spacing changes horizontally or vertically.

Practice Exercise 66

Space Controls

1. Open the Customer 4 form in Design View. 2. Drag to select the Customer Number, Store Name, Region, Credit Limit (do not select the note field) bound and unbound controlsSize and

SpaceTallest Click in a blank area of the form to deselect the controls. 7.18 Hiding The Ruler

You can hide or display the ruler in Design View. These scales are useful when you want to create controls that are a specific size, or place controls in a specific location.

Practice Exercise 67 Hid The Ruler

Open the Customer form in Design ViewArrange Ribbon

TabSize/SpaceRuler Size/SpaceRuler . 7.19 Snap to Grid Feature

Access provides several features to help you size and position controls on a form. The grid in Design View is a series of small points and lines in the Design Window. These points and lines (gridlines) help you position controls. When the Snap to Grid feature is activated, all controls added to the view are automatically positioned on grid points. Both the Grid and Snap to Grid features are enabled by default and can be disabled as desired.

Practice Exercise 68 Snap To Grid

Open the Customer form in Design ViewArrange Ribbon TabSpace/Size

.

Page 57: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 56

7.20 Field List

If a form or report is based on a table or query, you can display its Field List. This option allows you to easily add fields to the view.

The Field List appears as a box that “floats” above Design View. “Floating” means that you can drag the Field List by its title bar to reposition it anywhere on the screen. This option allows you to move the Field List to a more convenient location while you work. The Add Existing Fields button acts as a toggle. You click it to display the Field List and click it again to close. You can also close the Field List by selecting the Close button on the title bar.

Practice Exercise 69 Field List

1. Open the Customer form in Design ViewDesign Ribbon Tab.

2. Add Existing Fields Drag the field list to the bottom of the form Drag it back to the right edge.

7.21 Adding A Field

When you add a field to a Form or Report from the Field List Task Pane, the field will be Bound to the table. If the table you select is unrelated to the table in your record source, a relationship is automatically created, or Access prompts you to do so. When you add a blank field it is considered Unbound to the table until you connect it using the Form/Report Properties Source Control.

Practice Exercise 70 Add Field

1. Open Customer Data Entry form in Design View.

2. Design Ribbon Tab Add Existing Fields . 3. Drag Customer Number onto the form, to just above the Store Name controlRelease the mouse buttonMove the fields using the upper left control handle.

Page 58: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 57

7.22 Properties Of An Object

Every object in Access has properties that define its characteristics. Database objects such as tables, queries, and forms, have very general properties such as their names and descriptions. Other objects, such as fields in a table or controls on a form, have many properties that control their appearance such as font size and color, the number of decimal places, and the control source. The properties of objects are grouped into five categories: Format - Specifies the appearance of objects, such as the font characteristics,

position and size of a text box, or whether or not scroll bars appear on a form. Data - Determines the characteristics of the data displayed, such as the data’s

control source, default value, or whether or not it can be edited. You can change the data source for an individual control or for the entire form.

Event - Specifies a procedure that Access executes when an event occurs. Some examples of events include selecting a control (OnClick), deleting data (OnDelete), and opening the form (OnOpen). The procedure can be an expression, a macro, or a Visual Basic for Access routine.

Other - Shows additional features of the control such as the name of the control or whether or not a control is in the tab order.

All - Displays all the properties of the object in one list. You can open the Property Sheet by pressing the F4 Key on the keyboard.

Practice Exercise 71 Properties

Open the Customer Sales 5 form in Design ViewClick the Sales to Date text boxPress the F4 KeyClick the All tabScroll down the All page to view the properties of the control.

7.23 Control Property

The Properties of a Control define many of its aspects including the source of the information displayed in the control, its name, if it is displayed or hidden, and its appearance (font size, color, size, position, etc.). For example, you may have a form with records you want to keep constant. You can select No in the form’s Allow Edits property box to prevent any editing of the records. You can change the properties of several controls at once. For example, you can select several text boxes and change the font type and size for all of them at the same time, rather than individually.

Page 59: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 58

Practice Exercise 72 Control Property

1. Open the Customer Sales 5 form in Design View 2. Display the property sheet for the Sales to Date text box.

Format TabFormat property

Format Dropdown Currency

3. Click the Sales to Date label On the Format property sheet, change the Width property to 2cm and press the Enter Key. 4. Click the Sales Rep label on the form and change the Width property to 2cm. Switch to Form View.

7.24 Datepicker Control

This will allow you to use a little calendar to choose a date instead of typing in the date. Add a text box and set its properties to the proper format. Then set the Show Date Picker property to “For Dates.”

Practice Exercise 73 Datepicker Control

1. Select the Orders TableCreate Ribbon TabFormViewDesign View. 2. Select the Order Date field PropertiesFormat Tab Show Date Picker: For Dates. 3. Preview the Form in Form View to see the Date Picker property result.

7.25 Record Selectors

Record Selectors = No

7.26 Adding A Rectangle

You can draw a rectangle on a form or report. Note: Hold the Shift Key to draw a perfect square.

Practice Exercise 74

Rectangle

1. Open the Customer 5 form in Design View.

2. Design Ribbon TabRectangle Drag a rectangle around the Sales fields. 3. Switch to Form View to see results.

7.27 Adding a Line You can draw a line on a form or report. Lines can enhance forms and reports

by separating particular areas. Note: Hold the Shift Key down and draw the line straight.

7.28 Adding A Label

You can add text to a form or report. Text usually takes the form of a label and is not bound to a field. Labels can be used for data entry instructions on a form or for identifying groups of controls on a report.

Page 60: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 59

Practice Exercise 75 Add A Label

1. Open the Customer Sales 5 form in Design View. 2. Design Ribbon TabControls

Ribbon GroupLabels Place the label in a blank location. 3. Type Mike’s Sporting GoodsPress the Enter KeyFormat the text.

7.29 Conditional Formatting

You can use Conditional Formatting in forms and reports to change the appearance of controls or to change the appearance of the text within a control, depending on one or more conditions. For example, you may want to format negative numbers in a different color font, so as to draw attention to records that may need further action.

Practice Exercise 76

Conditional Format

Continue from the previous exercise. 1. Open the Customer Sales 5 form in Design ViewClick the Credit Limit field Detail sectionFormat Ribbon Tab

Conditional Formatting New Rule. 2. In the Condition 1 section, make sure the first box is set to Field Value Is. 3. The second box should be set to greater than. 4. In the third box type 5000. 5. Select the Font Color button, and select Red .

Preview the report.

7.30 Format Painter

You can use the Format Painter button in the Font Group on the Design Ribbon Tab to copy the style of a specific object and apply it to other objects. This feature saves time when multiple formats have been applied to an object and you want to format other objects with the same formats.

Label

Page 61: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 60

Student Project G - Manipulating Controls

1. File TabOpenLayoutX.accdb. 2a. Open the Project Form 1 form in Form View. 2b. Switch the view to Layout View. 2c. Switch the view to Design View. 2d. Drag to select all the controls on the form. 2e. Add the selected controls to a Stacked Layout. 2f. Remove the Total Sale control from the layout, and move it to the bottom of the form. Note: You may have to remove the layout. 2g. Use the property sheet to change the Total Sale control to display a currency format. (Hint: Select the Total Sale text box and use the Format property.) Then, close the property sheet. 2i. Switch to Form View to view the changes.

3a. Open the Project Form 2 form in Design View. 3b. Select the Course Name and Trainer Initials controls. 3c. Delete the selected controls. 3d. Reduce the size of the Project ID text box so that it is slightly longer than the text it contains. 3e. Select all the controls on the form. 3f. Size all the selected controls to the widest control on the form. 3g. Select the Start Date and End Date controls. 3h. Move the selected controls up until they are directly below the Client ID controls. 3i. Move the Total Sale controls directly under the End Date controls. 3j. Open the Field List, and add the Trainer Initials field to the form below the Total Sale control. 3k. Add all the controls to a Stacked Layout, set the Control Padding to medium. 3l. Switch to Form View to view the changes.

4a. Open the Project Form 3 form in Design View.

Page 62: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 7 - Form and Report Design

Page 61

4b. Add a label at the top right side of the form. Enter the text Mike’s Training Corp. 4c. Add a rectangle around the Mike’s Training Corp. label and the logo image. 4d. Draw a horizontal line across the bottom of the form. (Hint: Hold the Shift Key to draw a

straight line.) 4e. Use the Undo feature to reverse the previous action. 4f. Use the Redo feature to redo the reversed action. 4g. Switch to Form View to view the completed form. 4h. Close all forms and save them. 4i. Close the database file.

Page 63: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 62

Chapter 8 - Advanced Form Design In this chapter, you will learn how to use forms in Design View, create a Combo Box, edit List Items, create a List Box, create an Option Group, add a Logic Control, set the Tab Order automatically, set the Tab Order manually, form Header and Footer, and create a Blank Form.

Concept Explanation / Command String in italic. Practice Exercise 77 File TabOpenForm.accdb. Use this database for the entire chapter.

Make sure the ruler is open for all the exercises. 8.1 Forms in Design View

You can create or customize three sections in Design View: Detail Section – This section contains the information from the table or query. You can create controls in the Detail section that allow you to display or enter information. Access provides a variety of control types you can add to the form to simplify the data entry process. Form Header and Form Footer sections - This displays at the top and bottom of a form in Form View. If you print the form, these sections appear at the top of the first page and at the bottom of the last page. You can also place controls, including images, labels, and fields in the form header or footer. Page Header and Page Footer sections - This displays at the top and bottom of the form in Design View. They do not appear in Form View. Rather, they display at the top and bottom of every page when the form is printed.

8.2 Anchoring Tool

This will Anchor or Reposition the Form fields to the Anchoring position chosen. For example, if anchored to the Top Left corner (most desirable position) and the form area is resized, the Anchor will automatically move the Form Fields to the proper position.

Practice Exercise 78 Anchoring Tool

1. Create Ribbon TabForm Wizard. 2. Which Fields do you want on your form? Tables/Query: Table: Reps Selected Fields: Add all fields .

2. What Layout would you like for the Form? Columar . 3. What title do you want for the form? frmReps .

4. Select all the form fields in Design View. 5. Arrange Ribbon TabAnchoringTop Right. 6. Home Ribbon TabViewForm View. 7. Home Ribbon TabViewDesign View. 8. Arrange Ribbon TabAnchoringTop Left. 9. Home Ribbon TabViewForm View.

Page 64: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 63

8.3 Combo Box

You can create a Combo Box on a form. A Combo Box provides you with a list of values from which you can choose. Choosing from a list is much faster and more accurate than remembering a value to be typed. However, you can also type a value directly into a Combo Box if the appropriate value is not available from the list. A Combo Box can be bound to a field, meaning that when you select or enter a value, that value is entered into that field in the corresponding table. A Combo Box can also be Unbound, meaning that when you select or enter a value, it is held in memory to be used in another control or calculation.

8.4 Combo Box Wizard

Access provides a Combo Box Wizard that guides you through the process of creating a Combo Box. You can select the list of values from an existing table or query, or you can create the values for the list yourself. If you choose to select the list from an existing table or query, the wizard prompts you to enter the table or query and the field name. If you choose to create the list of values yourself, the wizard displays a column for the entries. Either way, once the values are entered into the wizard, you then specify whether the values should be entered into a field in the table or held in memory for later use. You complete the Combo Box by entering a label.

Page 65: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 64

Practice Exercise 79 Combo Box

1. Open the Order Entry form in Design View.

2. Design Ribbon TabDrag the Combo Box to the form. 3. I want the combo box to look up the values in a table or query . 4. TablesTable: Reps . 5. Double-click INITIALS . 6. . 7. Store that value in this fieldClick Store that value in this field Sales Rep . 8. Type Sales Rep . Move the Sales Rep label so that it is lined up with the Customer ID label above it. Move the Sales Rep combo box so that it is lined up with the Customer ID text box above it. Click in a blank area of the form to deselect the combo box.

8.5 Editing List Items

When you create a Lookup List in a form, you can now allow users to edit the list items using the Edit List Items dialog box. If you do not want users to be able to edit the list, you can also disable this property.

Practice Exercise 80

Edit List Items

1. Open the Items 2 form in Design View. 2. Click on the color fieldPress the F4 key to display the property SheetData tabClick on the Row Source Click on the and add Red. 3. Test it out by displaying the form. Notice that when you select on the arrow in the Color field, the new option has been added to the list.

8.6 List Box

You can create a List Box on a form. This provides you with a list of values from which you can choose which is much faster and more accurate than remembering a value to be typed. A List Box can be bound to a field, meaning that when you select or enter a value, the value is entered into a field in the corresponding table.

Page 66: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 65

8.7 List Box Wizard The List Box Wizard guides you through the process of creating a List Box. You can select the list of values from an existing table or query, or you can create the values for the list yourself. If you choose to select the list from an existing table or query, the wizard prompts you to enter the table or query and the field name. If you choose to create the list of values yourself, the wizard displays a column for the entries. Either way, once the values are entered into the wizard, you then specify whether the values should be entered into a field in the table or held in memory for later use. You can set the default value for a List Box by opening the property sheet and typing the desired value in quotation marks in the Default Value property box on the Data page.

Practice Exercise 81 List Box Wizard

1. Open the Order Entry 2 form in Design View.

2. Design Ribbon Tab List Box Click just under the Shipping Cost text box. 3. I will type in the values that I want . 4. Number of columns: 1Press the Tab KeyType US MailPress the Tab KeyEnter the following values under Col1 in the wizard, pressing the Tab Key after you type each value: UPS, DHL, Emery, FedEx . 5. Store that value in this fieldStore that value in this field Shipping Method . 6. Type Shipping Method .

Reduce the height of the Shipping Method list box by dragging the bottom border up. Line up the Shipping Method label with the Shipping Cost label above it. If necessary, move the Shipping Method list box to left align with the Shipping Cost text box above it. Click in a blank area of the form to deselect the list box.

Page 67: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 66

8.8 Option Group

You can create an Option Group on a form. This provides you with a limited set of values from which you can choose which is often much faster and more accurate than remembering a value to be typed. With an Option Group, you can only select one option from the set of alternatives. Therefore, Option Groups are best utilized when there are five or less values from which to choose. Adding more than five values to an Option Group can crowd a form and is less effective for quick data entry. An Option Group has a frame that encloses the set of values. These values appear beside option buttons or check boxes, or on top of toggle buttons.

8.9 Option Group Wizard

The Option Group Wizard guides you through the process of creating an Option Group. An Option Group can be bound to a field in a table or query. However, only the frame is bound to the field. Within the frame, Access assigns each option a numeric value, starting with the number 1. When the option is selected, this numeric value is entered into the corresponding field. Access assigns a number because the value of an option group cannot be text. For example, if a product comes in three colors (white, black, and green), you can use an Option Group in an order entry form to select the color being ordered. By default, Access assigns the number 1 to the White option, the number 2 to the Black option, and the number 3 to the Green option. You only see the White, Black, and Green options on the form, but Access actually stores the assigned numbers in the corresponding field in the table.

Practice Exercise 82 Option Group

1. Open the Order Entry 3 form in Design View.

2. Design Ribbon Tab Click below the Sales Rep label. 3. Type Smaller marketsPress the Tab KeyType Medium markets on the second row, press the Tab Key and type Large metro markets on the third row . 4. No, I don’t want a default . 5. Store the value in this fieldClick Store the value in this field Scroll as necessary and click Customer Type . 6. Check boxes Raised . 7. Type Customer Type . Click the Note text box and move the Note field down to remove the overlap with the Option Group. Click in a blank area of the form to deselect the Option Group.

Page 68: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 67

8.10 Logic Control

Some tables contain fields that have a Yes/No field type. In fact these fields can contain a Yes (True) value, a No (False) value, or no value at all. When working with a form that contains a Yes/No field, you can create a Logic Control that is bound to the Yes/No field. Logic Controls give a visual display of the value in a Yes/No field, such as a check box where a check mark appears when the field value is Yes and does not appear when the value is No. Another type of Logic Control is the toggle button, which appears “sunken” for a value of Yes and “raised” for a value of No. The Logic Control for a field with a null value (neither Yes nor No is chosen) appears the same as the field with a No value. Logic Controls improve the visual effectiveness of a form and facilitate data entry. With a Logic Control, the value of a Yes/No field is selected with a single click of the mouse button rather than multiple keystrokes. The way in which the different controls indicate a Yes or No value are described in the following table:

Control Appearance Toggle button Appears “sunken” with a Yes value and “raised”

with a No value. Option button Contains a dot with a Yes value and appears

empty with a No value. Check box Appears checked with a Yes value and

unchecked with a No value.

Practice Exercise 83 Logic Control

1. Open the Order Entry 4 form in Design View. 2. Design Ribbon TabCheck Box Click below the Shipping Method label. 2. Click on the Check BoxPress the F4 KeyClick the Data tab Control Source Scroll as necessary and click CatalogPress the F4 KeyRename the label to Send a Catalog? Press the Enter Key. Click in a blank area of the form to deselect the Logic Control. Switch to Form View and scroll through the records. Since the Logic Control (the check box) is now bound to the Catalog Field, it reflects the value of the Catalog Field for each record by appearing checked or unchecked.

8.11 Tab Order

The Tab Order determines the order in which form fields and controls are selected when you press the Tab Key during data entry. The default Tab Order is the order in which the fields or controls were added to the form. If you have added, rearranged, or deleted fields or controls, the Tab Order may not be suitable for data entry. You can choose to have Access automatically rearrange the Tab Order to reflect the order of the fields on the form. The fields are then accessed from left to right across each row.

Page 69: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 68

Practice Exercise 84 Set Tab Order

Automatically

1. Open the Order Entry 5 form in Form ViewPress the Tab Key to navigate through the controls on the form. Notice the order in which each control is selected.

2. Switch to Design ViewDesign Ribbon Tab Tab Order Switch to Form View. Press the Tab Key and notice that the fields and controls are selected from left to right across each row. Switch back to Design View.

8.12 Tab Order Manually

The Tab Order determines the order in which form fields and controls are selected when you press the Tab Key during data entry. The default Tab Order is the order in which the fields or controls were added to the form. If you have added, rearranged, or deleted fields or controls, the Tab Order may not be suitable for data entry. You can adjust the Tab Order manually to reflect whatever order is best for your data entry needs.

Practice Exercise 85 Set Tab Order Manually

1. Open the Order Entry 6 form in Design View.

2. Design Ribbon TabTab Order Click the record selector next to Order DateDrag the field between Frame34 and Shipping Date .

Practice Exercise 86

Move A Tab Order

Open the Tab Order dialog box. Select the Note field and drag it to the end of the list. Close the Tab Order Dialog Box. Switch to Form View. Press the Tab Key and notice the new tab order. Switch back to Design View.

8.13 Blank Form

You can create a form from scratch in Design View. For example, if a form does not currently exist for a particular table or query, you can create one using the fields in the selected table or query. You can then determine the design of the form by adding fields, control, and options.

Practice Exercise 87 Create a Blank Form

1. Create Ribbon Tab .

2. Design View

3. Double-click Line Items in the Field List 4. Drag the Order Number, Product ID, and Quantity fields to the 2" mark on the horizontal ruler. Click in a blank area of the form to deselect the controls. Space the controls vertically on the form and size them to fit.

8.14 Layout View One advantages of using the Layout View is you can modify the properties and see the results in the Layout View. ViewLayout View.

Page 70: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 8 - Advanced Form Design

Page 69

Student Project H - Using Advanced Form Design

1. File TabOpenFormX.accdb. 2. Open the New Payment Form in Design View. Display the ruler, if necessary. 3. Create a Combo Box for the trainers’ initials just below the Payment Date text box. 4. Indicate that the Combo Box should look up values in a table as the source for the values in the

list. Select Table: Trainer as the table and include the Initials Field in the Combo Box. Accept the default sort order and column width. Store the values entered in the Combo Box in the Trainer Initials Field and label the Combo Box “Trainer Initials.”

5. Create a List Box for the credit rating just below the “Trainer Initials” Combo Box. 6. Indicate that you want to type in the values for the List Box. Use one column and type the values

A, B, and C as separate entries. Store the values entered in the List Box in the Credit Rating Field and label the List Box Credit Rating.

7. Reduce the height of the List Box so that it displays only one line of text. Move the controls under, and left-aligned with the “Trainer Initials” controls.

8. Select the Project ID, Payment Date, Trainer Initials, and Credit Rating Bound Controls (text boxes) and size them to the narrowest size. Then, vertically space them equally.

9. Create an Option Group just below the Total Sale text box. 10. Type Yes and No as the label names and select Yes as the default choice. Change the default

value of the Yes label to -1 and the No label to 0. Store the value entered in the Option Group in the Recorded Field. Use Option buttons as controls and select the Raised style. Enter Recorded? as the label.

11. Open the Tab Order dialog box and set the tab order automatically. 12. Switch to Form View and press the Tab Key as necessary to view the Tab Order. Return to

Design View. 13. Create a custom Tab Order. Move the Payment Date field above the Amount Paid field and

close the Tab Order dialog box. 14. Display the form header in Design View and create a label with the text Payment Form in the

left side of the form header. Note: Right-Click on the Form.

15. Switch to Form View and create the following new record.

Field Value Project ID: 23 Payment Date: 10/3/03 Amount Paid: 600 Trainer Initials: EK Credit Rating: B Recorded: No

16. Close the form and save it. 17. Close the database file.

Page 71: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 70

Chapter 9 - Advanced Report Design In this chapter, you will learn how to add report sections in Design View, create a Calculated Control, create a Running Summary, insert a Date/Time Control, insert a Page Break, change the Report Margins, use the Label Wizard, and create a report without using a wizard.

Concept Explanation / Command String in italic. Practice Exercise 88 File TabOpenReport.accdb. Use this database for the entire chapter. 9.1 Report Sections

You can create or customize three sections in Design View: Detail Section – This section contains the information from the table or query. You create controls in the Detail section that display information, and can display either one record per page or multiple records per page. Form Header and Form Footer section - This section displays at the top and bottom of the report in Design View. When you print the report, these sections appear at the beginning and the end of the report only. The Header can be used for report titles, while the Footer can be used for report totals or other summaries. Page Header and Page Footer section – This section displays at the top and bottom of the report in Design View. When the report is printed, these sections appear at the top and bottom of every page. Page Headers and Footers can contain images, lines, text, or any other controls you want printed on every page.

Practice Exercise 89

Reports Section 1. Open the Items report in Design View. 2. Right-click on the grid background area of the report

Report Header/Footer and Page Header/Footer . 3. Design Ribbon TabControls Ribbon GroupLabel Add a label to the center of the Report HeaderEnter the text: Order Entry Report. 4. Add a page number to the Page Footer from the Design Ribbon Tab.

5. Preview the report in the Report View and Print Preview .

Page 72: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 9 - Advanced Report Design

Page 71

9.2 Calculated Control

You can add a calculated control to a form or report. This is not bound to a field. It contains an expression that uses information from fields to calculate a result. The result is not stored in a table, but is calculated when the report or form is run. You can type the expression that calculates the result directly into the control or open the property sheet and type the expression into the Control Source Property Box on the Data page. A Calculated Control in a form or report cannot be based on another Calculated Control in the form or report. However, you can base a Calculated Control on a calculated field in a query.

Practice Exercise 90 Calculated Control

1. Open the Items by Order report in Design View and display the ruler. 2. Display the Item Total column in the Page Header section.

3. Design Ribbon TabControls Ribbon Group Click in the Detail section under the Item Total labelType =[unit price]*[quantity] Press the Enter Key. 4. Design Ribbon TabProperty SheetFormat Tab Format Property Currency. 5. Select Quantity text box and the new calculated control text box Arrange Ribbon TabAlign DropdownTop.

9.3 Date/Time Control

You can insert controls that display the current date and/or time in a report. Each control updates automatically every time the report is previewed or printed. The Date and Time Dialog Box inserts a control that uses the =Date() function to display the current date.

Practice Exercise 91 Date/Time

1. Open the Items by Order 5 report in Design View and maximize the window. Scroll as necessary to view the Report Header section. 2. Design Ribbon Tab Include Time to deselect it . 3. Drag the Date Control to the right of the label in the Report Header section. 4. Preview the report. Scroll as necessary to view the date in the report header. Switch back to Design View.

9.4 Page Break

When you print a report, Access automatically starts a new page when necessary. You can control the pagination by inserting a page break. You can insert a page break in the Group Footer section to place each group on its own page, or you can insert a page break in the Report Header section to create a separate title page for a report.

Practice Exercise 92 Insert Page Break

1. Open the Items by Order 6 report in Design View.

2. Design Ribbon TabControls Ribbon GroupInsert Page Break . 3. Click near the bottom of the Report Header section, click in a blank area of the form to deselect the dots indicating the page break. 4. Preview the report in a two-page view. Notice that the report header appears by itself on the first page. Switch back to Design View.

Page 73: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 9 - Advanced Report Design

Page 72

9.5 Page Setup

By default, the margins for a report are one inch on all sides. You can control the margin settings to fit more or less data on a page as necessary. The margins you set for a report are saved and applied each time you print the report. Also, this is where you will change the number of columns. ViewDesign ViewPage Setup Ribbon TabPage Setup.

Practice Exercise 93 Margin

1. Open the Items by Order 7 report in Print Preview.

2. Page Setup Double-click in the Top box

3. . 4. Preview the report to view the completed report with the new margins.

9.6 Label Wizard

Access has a Label Wizard that guides you through the process of creating a report and printing labels. You can choose from many standard types of labels, or you can create your own custom label definition.

Page 74: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 9 - Advanced Report Design

Page 73

Practice Exercise 94 Label Wizard

1. Click on the Customers Table Create Ribbon TabLabels . 2. This wizard creates custom or standard labels: Filter by manufacturer Avery Scroll as necessary and click J8360 . 3. What font and color would you like your text to be? Font name Times New Roman .

. 4. What would you like on your mailing label? CustomersDouble-click Store NamePress the Enter Key. Create the following label. Insert the correct punctuation by typing a comma and space after the City field, and a space between the State/Province and Postal Code fields. Two lines under the Country field, add the text Attn: and insert the Contact Name field.

5. What fields would you like to sort by? Double-click Store Name . 6. What name would you like for your report? Type Customer Labels . Notice that the labels appear in three columns. The address labels are printed in alphabetical order by store name. Close the Print Preview Window and the label report.

9.7 Report Without Using A Wizard

You can create a report from scratch in Design View. For example, if a report does not currently exist for a particular table or query, you can create one using the fields in the selected table or query. You can then determine the design of the report by adding fields, controls, and options.

Page 75: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 9 - Advanced Report Design

Page 74

Practice Exercise 95 Report Wizard

1. Create Ribbon TabBlank Report .

2. Design Ribbon TabAdd Existing Fields . 3. Add the fields in the Customers table: Customer Number, Store Name, Contact Name, and Sales Rep. 4. ViewDesign ViewSelect all control fieldsRight-ClickLayout Remove Layout Space out the names to fit on the screen. 5. Display the report header and footer sections: Right-Click on the Details section barReport Section. 6. Add a left-aligned label to the Report Header section called Customer Contact Information.

Student Project I - Using Advanced Report Design

1. File TabOpenReportX.accdb. 2. Create a new Blank Report in Design View based on the

Project Table. 3. Add the Client ID field in the upper left corner of the Detail

section. Below the Client ID field, add the Course Name, Trainer Initials, and Students fields to the report in the Detail section.

4. Add a label to the left side of the report header. Enter the text Client Information. 5. Preview the report. Then, close the report and save it as Client Info. 6. Add the Amount Paid field in the Payments table. Use the Add

Existing Field button in the Design Ribbon Tab. 7. Add a Calculated Control below the Amount Paid field to

calculate the profit margin of each project. The calculation should use the following formula: =[Amount Paid]*.50. Format the calculation as currency. Change the text in the label to Profit Margin. If necessary, resize the label to view all the text.

8. Draw a rectangle around the data area. Change the Shape Fill to Transparent and increase the Shape Outline Thickness.

9. Preview the report. Notice the profit margin calculation. Then, switch back to Design View.

10. Display the Report Header/Footer section. 11. Insert the date only using the default date format. Move the date control to the Page Footer

section. 12. Adjust the top and bottom page margins.

13. Print on multiple columns: Page Setup Ribbon TabPage Setup 13. Preview the report to see the new margins. Notice that the date appears on each page of the

report. Close the report, saving the changes.

Page 76: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Chapter 9 - Advanced Report Design

Page 75

Student Project J – Print Labels Use the Label Wizard to create labels based on the Trainer Table. Use the Avery L7161 labels

and the default font and color settings. Include the First Name and Last Name fields, separated by a space on the same line. Sort the labels by the Last Name and First Name fields. Use Labels Trainer as the name of the report.

Page 77: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 76

Appendix A - Naming Conventions

A.1 Table Naming Conventions

A Naming Convention is a systematic way of naming objects. In this course, we will use a Naming Convention that follows two rules. First, every Table, Query, Form, and Report object will be named with a three-character prefix. Second, all objects will have no spaces in their names. In addition, the table name can have up to 64 characters and can include letters, numbers, and spaces. They cannot contain a period (.), an exclamation point (!), a back quote (`), brackets ([]), or ASCII control characters.

tbl Customers

A.2 Naming Conventions

Tables tbl General Purpose Table tdd Used for a Drop Down list tjn Junction Table Queries qry Select Query qap Append Query qdl Delete Query qup Update Query qxt Cross Tab Query qmt Make Table Query qsb Sub Query qtl Total Query

Forms frm Regular Form dlg Used as a Dialog Box fdd Form for Drop Down data fmn Main Form fsb Sub Form fds Datasheet Form Reports rpt Report rsb Sub Report lbl Label Report rgr Graph Report Macros mcr All Purpose Macro

Page 78: Microsoft Access 2013 Relationships, Queries, Forms Only ... · Access 2013 - Level 2 Relationships, Queries, Forms, Reports . Access database administrator s that have database creation

For Eva

luatio

n Only

Page 77

Access 2010/2013 Level 2 Index Action Queries ................. 40 Add Fields ........................ 24 Adding A Field ................ 56 Aligning Controls ............ 55 Anchoring Tool................ 62 And / Or ........................... 28 And Operator .................. 26 Append Query ................. 43 Atomic .............................. 14 Between And Operator ... 28 Calculated Field ........ 33, 34 Candidate Key ................. 14 Cascade Delete ................... 8 Cascade Update ................. 7 Columar Layout .............. 50 Concatenation in a Query

...................................... 37 Control Margins .............. 54 Control Padding .............. 54 Control Property ............. 57 Controls ............................ 52 Crosstab Query Wizard . 44 Datasheet Layout ............ 50 Date Values ...................... 25 Datepicker Control ......... 58 Delete A Column ............. 24 Delete Query .................... 43 Deleting A Join Line ......... 5 Deleting Controls ............ 53 Dependent Field .............. 14 Determinant Field ........... 14 Export A Query ............... 22 Exporting Data ................ 21 Expression Builder .......... 29 Field List .......................... 56 Field List Worksheet ....... 15 Filtering a Query ............. 37 Find Duplicates Query

Wizard ......................... 45 Find Unmatched Query

Wizard ......................... 45 First Normal Form .......... 15 Foreign Key ....................... 4 Form

Adding a Label ............ 58

Adding a Line .............. 58 Adding a Rectangle ..... 58 Blank Form ................. 68 Combo Box .................. 63 Combo Box Wizard .... 63 Conditional Formatting

.................................. 59 Design View ................. 62 Editing List Items ....... 64 List Box ........................ 64 List Box Wizard .......... 65 Logic Control .............. 67 Manual Tab Order ..... 68 Option Group .............. 66 Option Group Wizard 66 Tab Order .................... 67

Format Painter ................ 59 Fourth Normal Form ...... 16 Function Query ............... 34 Importing Data ................ 20 Inner-Join Query ............. 17 Insert Column .................. 24 Is Not Nul ......................... 30 Join Related Tables ........... 3 Join Type ............................ 6 Junction Tables ................. 6 Justified Layout ............... 51 Layout View ..................... 68 Left Outer-Join ................ 17 Like String ....................... 25 Linked Table Manager ... 23 Linked Tables .................. 22 Linking ............................. 22 Make Table Query .......... 40 Many-to-Many

Relationship ................... 6 Move A Column .............. 24 Moving Controls .............. 52 Multi-Field Key ................. 4 Multivalued Fields ........... 36 Naming Conventions ....... 76 Non-adjacent Controls .... 52 Non-Key Field .................. 14 One-to-Many Relationship 5 One-to-One Relationship .. 4

OR Condition ................... 27 Or Row ............................. 24 Orphan Records ................ 7 Page Setup ........................ 72 Paired Control ................. 53 Parameter Query ............. 36 Primary Key ...................... 4 Properties of an Object ... 57 Record Selector ................ 58 Recordset .......................... 24 Referential Integrity .......... 7 Relationship ..................... 24 Relationship Window ........ 4 Removing Controls .......... 51 Report

Adding a Label ............ 58 Adding a Line .............. 58 Adding a Rectangle ..... 58 Calculated Control ...... 71 Date/Time Control ...... 71 Label Wizard ............... 72 Page Break ................... 71 Sections ........................ 70

Right Outer-Join ............. 17 Ruler ................................. 55 Second Normal Form ...... 15 Show Check Box .............. 32 Show Table ....................... 24 Sizing a Control ............... 53 Sizing Controls ................ 54 Snap to Grid Feature ...... 55 Sort ................................... 32 Spacing Controls ............. 55 SQL Database Structure . 16 SQL View ......................... 32 Stacked Layout ................ 51 Tabular Layout ................ 50 Text Values ...................... 25 Third Normal Form ........ 16 Top Values In A Query ... 32 Totals Row ....................... 35 Update Query .................. 42 Using Comparison

Operators ..................... 25 Wildcard Character ........ 30