As your databases continue to evolve, you will need to incorporate advanced queries and reports. This chapter addresses how to create and use action

Similar documents
Access Intermediate

Complete Quick Reference Summary

Access 2003 Introduction to Report Design

Access Intermediate

Access - Introduction to Queries

Microsoft Access XP Queries. Student Manual

Tutorial 3 Maintaining and Querying a Database. Finding Data in a Table. Updating a Database

eschoolplus+ Cognos Query Studio Training Guide Version 2.4

PowerPoint Presentation to Accompany GO! All In One. Chapter 13

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

Microsoft Access 2010

Advanced Queries: Moving Beyond the Select Query Instructor: Edwin V. Bonilla

Create and Modify Queries 7

Query Studio Training Guide Cognos 8 February 2010 DRAFT. Arkansas Public School Computer Network 101 East Capitol, Suite 101 Little Rock, AR 72201

GO! with Microsoft Access 2016 Comprehensive

Access: Printing Data with Reports

CHAPTER 6 SUMMARY. Objective 1: Identify Good Database Design

Microsoft Access Illustrated. Unit B: Building and Using Queries

Creating a Crosstab Query in Design View

MIS Cases: Decision Making With Application Software, Second Edition. Database Glossary

Step 1: Create a totals query to show the total cost price and total sale price of the wine for each supplier.

Microsoft Access 2016

Microsoft Access 2016

Links to Activities ACTIVITY 4.1. Links to Activities Links to Activities

THE EXCEL ENVIRONMENT... 1 EDITING...

Microsoft Office Illustrated. Using Tables

Creating a Spreadsheet by Using Excel

Microsoft Excel 2010 Handout

Microsoft Office Specialist Access 2016

Copyright 2009 Labyrinth Learning Not for Sale or Classroom Use LESSON 1. Designing a Relational Database

Creating Reports in Access 2007 Table of Contents GUIDE TO DESIGNING REPORTS... 3 DECIDE HOW TO LAY OUT YOUR REPORT... 3 MAKE A SKETCH OF YOUR

Microsoft Access 5: Reports & Other Useful Functions

Name: Class: Date: Access Module 2

Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts. Microsoft Excel 2013 Enhanced

Microsoft Access 2016 Intro to Forms and Reports

Using Reports. Access 2013 Unit D. Property of Cengage Learning. Unit Objectives. Files You Will Need

Chapter 5: Hierarchical Form Lab

Microsoft Access XP (2002) - Advanced Queries

MODULE 5 DATABASES. Content

Access Intermediate

Database Tables Lookup Wizard Relationships Forms Subforms Queries Reports

Microsoft Access 2013

Microsoft Access 2013

When you pass Exam : Access 2010, you complete the requirements for the Microsoft Office Specialist (MOS) - Access 2010 certification.

Excel Tutorial 1

Microsoft Office Access Learn how to use the Query window in Design view. Tutorial 3b Querying a Database

Chapter 4: Single Table Form Lab

INTRODUCTION... 1 UNDERSTANDING CELLS... 2 CELL CONTENT... 4

Excel Tutorial 5: Working with Excel Tables, PivotTables, and PivotCharts. 6. You can use a table s sizing handle to add columns or rows to a table.

Database Design Practice Test JPSFBLA

Let s create another simple report from one of our queries available: Author Age query.

Excel 2007 New Features Table of Contents

Using Microsoft Excel

Access Module 2: Building and Using Queries

IT2.weebly.com Applied ICT 9713

Excel Shortcuts Increasing YOUR Productivity

Microsoft Certified Application Specialist Exam Objectives Map

Lesson Skill Matrix Skill Exam Objective Objective Number

Microsoft Excel 2010 Tutorial

-Using Excel- *The columns are marked by letters, the rows by numbers. For example, A1 designates row A, column 1.

Skill Exam Objective Objective Number

Glossary GLOSS.1. Building a Foundation with Microsoft Office 2013

New Perspectives on Microsoft Excel Module 5: Working with Excel Tables, PivotTables, and PivotCharts

WebIntelligence. Creating Documents

Shelly Cashman Series Microsoft Office 365 and Access 2016 Introductory 1st Edition Pratt TEST BANK

USING MICROSOFT ACCESS 2013 Guided Project 7-1

Kenora Public Library. Computer Training. Introduction to Excel

1.8.1 Research various database careers SE: 335

Using Microsoft Access

EXCEL 2003 DISCLAIMER:

SE: 4, 6, 31 (Knowledge Check), 60, (Knowledge Check) 1.2 Explain the purpose of a relational Explain how a database is

Enforce Referential. dialog box, click to mark the. Enforce Referential. Integrity, Cascade Update Related Fields, and. Cascade Delete Related

Word Module 5: Creating and Formatting Tables

Microsoft Office Illustrated Introductory, Building and Using Queries

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

USER MANUAL. Contents. Analytic Reporting Tool Basic for SUITECRM

Introduction to Microsoft Excel

Excel 2016: Part 1. Updated January 2017 Copy cost: $1.50

Getting started with Ms Access Getting Started. Primary Key Composite Key Foreign Key

AVANTUS TRAINING PTE LTD

ICDL & OOo BASE. Module Five. Databases

Content-Based Assessments

SUM - This says to add together cells F28 through F35. Notice that it will show your result is

CHAPTER 4: MICROSOFT OFFICE: EXCEL 2010

Part II: Creating Visio Drawings

Welcome to Cole On-line Help system!

Prepared By: Graeme Hilson. U3A Nunawading

Skills Exam Objective Objective Number. Creating crosstab queries Create a crosstab query

Productivity Tools Objectives 1

Using Microsoft Access

Index. B backing up 76 7

Introduction to Microsoft Excel 2016

Microsoft Excel 2007

Access 2013 Introduction to Forms and Reports

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

Office of Instructional Technology

Open Learning Guide. Microsoft Excel Introductory. Release OL356v1

Microsoft Access 2010

Microsoft Excel 2010

Table of Contents COURSE OVERVIEW... 5

Transcription:

As your databases continue to evolve, you will need to incorporate advanced queries and reports. This chapter addresses how to create and use action queries and how to create queries that perform more powerful tasks. In this chapter, you also learn how to use Design view to create and modify reports, including the use of subreports. 1

Student Learning Outcomes (SLOs) SLO 6.1 Understand action queries; create and use Update, Append, Delete, and Make Table queries. SLO 6.2 Use the Query Wizard to create a crosstab query, a find duplicate records query, and a find unmatched records query. SLO 6.3 Use the top values properly, explore and use date functions, and create a query with a subquery. SLO 6.4 Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report. SLO 6.5 Use Design view to add a control to a report; modify the size, location, font characteristics, and formatting properties of a control; and change properties of multiple controls. SLO 6.6 Use calculations in a control on a report, create a running total in a control, and concatenate text data in a report. SLO 6.7 Understand when to use a subreport, create a main report and a subreport, add a subreport onto a main report, and customize a subreport. 2

Case Study Placer Hills Real Estate will be used throughout this chapter for the Pause & Practice projects. 3

SLO 6.1 Understand action queries; create and use Update, Append, Delete, and Make Table queries. 4

SLO 6.1 Understand action queries; create and use Update, Append, Delete, and Make Table queries. An action query is another type of query in Access. You can use an action query to make changes to the data in a database. In this section, you learn how to create and use the four different action queries; an update query, an append query, a delete query, and a make table query. Understand Action Queries When creating action queries, it is important that you clearly define and understand the business task you need the query to accomplish, including knowing how frequently the task needs to be done. The following scenarios help to illustrate several different tasks, along with their frequency. A company closes a branch office and needs to assign employees to a different branch. This business task needs to be done only one time or very infrequently. A store manager needs to update the purchase cost of each item when the manufacturer who supplies goods to a store raises product prices. This business task might be part of a recurring process that happens periodically. 5

At the end of every semester, a clerk in a university equipment office needs to remove the equipment reservations from the reservation table. However, the university still needs to keep the reservation records in a history table. This business task involves using several action queries together. First the clerk appends the old reservations into a history table before deleting the records from the reservation table. You can automate each of the tasks described above using an action query. An action query makes a permanent change to the data in the database and the Undo button is not available to reverse the action. As a result, it is a good practice to make a backup copy of your database before you run any action query. This will allow you to restore your original data if the query does not work correctly. As additional protection, Access displays a message box alerting you to the change before executing an action query. The exact message varies depending on the type of action query. 5

SLO 6.1 Understand action queries; create and use Update, Append, Delete, and Make Table queries. Create an Update Query An update query changes data in the database. While you could open a table in Datasheet view and modify each record individually, an update query allows you to make the change to all records using one command. Create an Append Query An append query adds records into an existing table in a database. An append query does not move the records from one table to another, rather it puts a copy of the records into the destination table. Create a Delete Query A delete query deletes records from a table in a database. A delete query can save you a significant amount of time if you want to delete a number of records from a table. Create a Make Table Query A make table query creates a new table in a database and also copies the records into the new table. Organizations often use a make table query to create a history table, which they then use to store old records. For example, a university might store equipment reservations from previous semesters in a history table. Management could review the history table to analyze usage patterns on the equipment. A make table query can create the new table from fields in one or multiple tables. You can select which fields from a table should appear in the new table. You can copy all of the records or only the records that meet a specific condition. After the query executes, you need to designate a primary key in the new table. The new table you create does not have any relationship to the existing tables in the database. 6

SLO 6.2 Use the Query Wizard to create a crosstab query, a find duplicate records query, and a find unmatched records query. 7

SLO 6.2 Use the Query Wizard to create a crosstab query, a find duplicate records query, and a find unmatched records query. The Query Wizard is a tool that makes it easier to build four different types of queries. In this section, you will use three other types of query wizards: The Crosstab Query Wizard, the Find Duplicates Query Wizard, and the Find Unmatched Query Wizard-to create three special types of select queries. Each of these query wizard options is available in the New Query dialog box. Understand and Build a Crosstab Query A crosstab query summarizes data on two dimensions. The results of a crosstab query display in a row/column format, which makes the data easier to read and understand (compared to the results of a select query). When creating and using crosstab queries, keep the following points in mind: Crosstab queries are not appropriate in all databases. You must have data that can be summarized across two dimensions. Unlike the resulting datasheet from a regular select query, you cannot edit the results from a crosstab query. A crosstab query can get its data from a table or another query. If you need to use fields from more than one tale, you must first create a select query that combines the fields from the different tables. You can include up to three fields as row headings. The row headings are the field(s) that appear in the left-most column(s) of the grid. You must select one column heading field. The column heading is the field that contains the different values that display in the heading row of the results. When creating the query, you select the field to calculate and the aggregate function, such as Sum or Count, to use on that field. You can create a crosstab query using Query Design; however, it is much easier to create the query using the Crosstab Query Wizard. After you create a crosstab query with the Crosstab Query Wizard, you can edit it in Design view and make changes to any of the selections made during the wizard. You can also add criteria or sorting options to the query. 8

SLO 6.2 Use the Query Wizard to create a crosstab query, a find duplicate records query, and a find unmatched records query. Find Duplicate Records If duplicate records are present, two or more records in a table share the same values. Generally speaking, you should avoid having duplicate records in your database. When you follow good database design guidelines, you put in place features that prevent your database from allowing duplicate data. For example, when you designate a field as a primary key, Access will not allow you to have two records with the same value in the primary key field. Unfortunately, even when you practice good database design, you still may end up with duplicated data. Consider customers who forget their login IDs and passwords and create new accounts or a salesperson who accidently enters the same order twice. Having two records for the same customer, even though the login ID is different, or two records of the same order, even though the order number is different, results in duplicate data. You need to remove duplicated records in situations like these. Additionally, sometimes you may inherit a database that was poorly designed and does not have primary keys created, or you may import data from another source that contains duplicate data. Before you can create and enforce 9

a primary key, you need to find and remove duplicate data. Keep in mind that all duplicated data is not bad. For example, the same product number or salesperson ID appears on multiple sales records. You want to find and correct only data that clearly is a problematic duplication of existing data. A find duplicates query locates data that is duplicated in your database. You can create a find duplicates query using Query Design; however, it is much easier to create the query using the Find Duplicates Query Wizard. When the query is initially created in the query wizard, Access returns only records that have a match on the entire value in a field. You can edit the query after it is created to look for partial matches by adding criteria that uses wildcards. When you review the results of a find duplicates query, you may need to conduct further analysis to determine whether the records are actually duplicates. This may involve looking at data in other tables, conducting research, or talking with employees or customers. Before deleting duplicate records, change the foreign key connection of any related records in other tables so they are associated with the record that remains in the database. Find Unmatched Records Unmatched records are records in one table that do not contain any matching records in a related table. For example, imagine that San Diego Sailing wants to determine which boats have not been rented or a retail store wants to find out which products have not been purchased in the last quarter. This information can help these organizations make business decisions about reducing the price, running a promotional special, discontinuing a product, etc. The situations described in the previous paragraph do not indicate a problem with the database design. However, as noted in the previous description of the use of the find duplicate query, sometimes you may inherit a poorly designed database. Referential integrity may not have been enforced, resulting in records that do not have valid relationships. If this happened, you need to find the unmatched records and either remove them or connect them to valid records An unmatched records query compares records in two tables and determines which ones are not matched. You can create a find unmatched records query using Query Design; however, it is much easier to create the query using the Find Unmatched Query Wizard. If you create an unmatched records query because you are concerned about the design of your database, review the results of the query to determine appropriate action. This may involve looking at data in other tables, conducting research, or talking with employees or customers. You may determine that the unmatched records should be deleted or that they need to be matched to a record in a related table. 9

SLO 6.3 Use the top values properly, explore and use date functions, and create a query with a subquery. After completing SLO 6.3, complete Pause & Practice 6-1. 10

SLO 6.3 Use the top values properly, explore and use date functions, and create a query with a subquery. Queries provide a great deal of power and flexibility to help you accomplish many tasks in your database. As the number of records in your database increases, you can use query properties to limit the number of records that display in a result. Additionally, as the processing of your database becomes more sophisticated, you may need to write queries that use more complex functions or queries that use other queries as their data source. In this section, you learn how to create queries to deal with these more complex situations. Find the Top Values in a Query The Top Values query property limits the number of records that display in a query answer. This can be helpful when you want to focus attention on certain aspects of a business. For example, an organization may want to find out who its top performing salespersons were in the past year. The queries you have written so far have returned all of the records that meet the criteria. This is because the default setting of the Top Values property is All. For your top values query to function correctly, you must keep the following points in mind: 11

You must select either a fixed number of records or a percentage value. The preset choices are 5, 25, 100, 5%, 25%, and All. You can enter a different value if it is not one of the preset choices. When the query executes, the selected number or percentage of records display, starting with the first record that is in the query result. To have the query return the top values, you must sort the query results in descending order on the desired field. To have the query return the bottom values, sort the query results in ascending order. Understand and Use Date Functions in a Query Access has a variety of functions that allow you to work with dates. For example, you can use date functions to write queries that find the properties listed in the current month, find students who are 18 years old, or find products that are nearing their expiration dates. In this section, the date functions are explained in the context of using them with a query. However, you can also use date functions in other objects and controls that use expressions. As you start to work more with dates, it helps to know that Access internally represents each date as a serial number. The serial number is designated by the number of days the date is from January 1, 1900. For example, the serial number for 1/1/2017 is 42736, while the number for 1/2/2017 is 42737. This format allows Access to perform date arithmetic. Additionally, when working with many of the date functions, it is important to understand how Access represents the intervals (pieces) of a date. These are explained in the following Access Date Intervals table: Access Date Intervals For 4/15/2017 yyyy Year 2017 q Quarter (1-4) 2 m Month 4 y Day of year (1-365) 105 d Day (1-31) 15 11

w Weekday (1-7) 3 ww Week (1-52) 16 Many times an expression combines several functions. For example, to display the name of today s month, you write: MonthName(DatePart( m,date())) This expression uses the MonthName function to determine the actual name of the month. However, that function needs the month number. The month number comes from the DatePart function, which retrieves the month from the Date function. As you know, the Date function retrieves today s date from your computer. Don t worry; the description makes the process seem more complicated than it really is. Create a Subquery The query examples used so far have all used a table as the data source for a query. A query can also use another query as the data source. A subquery is a query that is used inside another query. Creating a query and then using it inside another query can be helpful when you have a common starting point (the original query) but want to customize it for additional purposes (the additional query). Sometimes using a subquery is a more efficient way to get the results you are seeking, but it depends on the size of the database and the design of the query. To incorporate a subquery, you follow the general process you have learned in this book to create a query. The only thing you do differently is to select the Query Name from the Queries tab of the Show Table dialog box, instead of selecting the Table Name from the Tables tab. 11

SLO 6.3 Use the top values properly, explore and use date functions, and create a query with a subquery. Access Date Functions Date() Retrieves the current system date. Date() 1/4/2017 DatePart() Determines a specific piece, or interval, of a date. DatePart( q,[datelisted]) DatePart( yyyy,#4/15/2017#) 4 2017 DateSerial() Converts values into a date value DateSerial(2017,2,20) 2/20/2017 DateAdd() Adds to a date. You must specify the value along with the interval. 12

DateAdd( yyyy, 3, [DateListed]) 12/17/2019 This example added 3 years to the DateListed. DateDiff() Determines the difference between two dates. You must specify the interval. DateDiff( d, [DateListed], Date()) 18 This example calculated how many days It has been since the property was listed. MonthName() Retrieves the name of the month number. MonthName(2) February WeekdayName() Retrieves the name of the weekday number. WeekdayName(7) Saturday 12

SLO 6.4 Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report. 13

SLO 6.4 Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report. While the skills you have previously learned while creating and editing reports with the Report Wizard and Layout view still apply. Design view provides additional flexibility and tools for creating and editing a report. Understand Report Sections A report can contain many different sections, explained in the Report Sections table. When you are viewing a report in Layout or Print Preview view, the sections are not as obvious as they are in Design view. You need to understand how each section works in order to build your reports correctly. Report Sections Report Header Print a report title or logo. Once, at the top of the first page. Report Footer Print report totals or other information at the end of the report. (In Design view, this 14

section appears below the page footer, but in other views, and when the report is printed, this section prints above the page footer.) Once, at the bottom of the last page above the page footer. Page Header Print column headings, page numbers, or dates. At the top of every page. (Prints below the report header on page 1.) Page Footer Print page numbers or dates At the bottom of each page. Group Header Print the group title/value. At the top of each group. Group Footer Print aggregate calculations for each group. At the bottom of each group. Detail Print the fields from each record. Once for every record. 14

SLO 6.4 Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report Review the different sections and their placement in Design view and in Print Preview. 15

SLO 6.4 Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report. Add or Delete Page and Report Sections in Design View When you create a report in Design view, Access automatically includes Page Header, Detail, and Page Footer sections. You can add or remove sections in a report as needed. Add or Delete Group Sections in Design View As you learned in Chapter 4, a report can have more than one Group Header and Group Footer section if you have multiple fields on which you want to group. Additionally, you add the Group Header and Group Footer sections independently, so you are not required to have both. Create a Report in Design View Creating a report in Design view provides you with the most flexibility. After you create the report, you can edit it to add the fields, labels, or other controls that you need. You can also add or remove sections on the report. 16

Understand the Report Data Source The Record Source property of a report regulates which database fields are available in the report. When a report is first created in Design view, the Record Source property is blank. When a record source is assigned, all of the fields that are included in the record source become accessible to the report. This allows you to reference the contents of a field without including it on the report. For example, consider a report in the Placer Hills database in which the Listings table is the record source. A text box on the report contains a formula to calculate the potential commission of a property listing. This formula uses the ListPrice field from the table; however, that field is not displayed in the report. Because the field is accessible through the record source, the calculation works correctly. After setting the Record Source property, you can add fields to the report. In Design view, you can also add table fields directly to the report from the Field List without first setting the Record Source property. In this case, Access automatically sets the value of the Record Source property to an embedded query, written in SQL. Recall that SQL stands for Structured Query Language, the underlying language in a relational database system. An embedded query automatically updates as you add and remove fields from the report. Only the fields that are included in the embedded query are accessible to the report. You can also add fields to an embedded query to make them accessible without having to add them as a field on the report. Add and Delete Fields in Design View Usually, one of the first tasks in building a report is to add the data fields. The data fields can come from tables or queries. When you add a field into a report, both a control bound to the table field and a label are created. Visually, the label has a transparent background while the control bound to the data field has a white background. Most of the controls are text boxes, but some are combo boxes or check boxes depending on the data type of the field. Recall that a label displays the name of the field if a value has not been entered into the Caption property. In Design view, the bound control displays the field name. Create a Parameter Report You have learned about using parameter queries to increase the efficiency and flexibility of your database. By creating a parameter report, you can also apply those benefits to the reports in your database. A parameter report asks the user to enter the specific criteria value for a field when the report is run. This allows you to create one report but have the contents displayed vary based on the value of the parameter that is entered. If a parameter query has already been created, you can assign that query to the Record Source property of the report. When you view the report, the Enter Parameter Value dialog box displays, allowing you to enter the desired value. If a parameter query does not exist, in Design view you can open the Query Builder of the Record Source property to add a parameter to the report. 16

SLO 6.5 Use Design view to add a control to a report; modify the size, location, font characteristics, and formatting properties of a control; and change properties of multiple controls. After completing SLO 6.5, assign Guided Projects 6-2 and 6-3. 17

SLO 6.5 Use Design view to add a control to a report; modify the size, location, font characteristics, and formatting properties of a control; and change properties of multiple controls. After adding the required fields, you typically will want to enhance the design of the report. Common improvements include adding titles and page numbers. As appropriate, you may also want to change the size or font of fields or the size or color of sections. Many times the modification can be made either by directly editing the control or section or by changing the corresponding property on the Property Sheet. The choice often depends on the precision needed, and both methods will be introduced in this section. For example, if you need a text box to be exactly 1 wide you should set the value in the Width property. If you just need it big enough to show the data, use the sizing handles to change the width. Add a Control to a Report One of the first modifications you often make is to add controls not associated with table fields. You can add controls such as text boxes, labels, images or lines to a report. Remember that each control you add to a report is assigned a default name 18

that combines the type of control along with a sequential number, such as Text3, Label10 or Line8. Adjust the Size of a Control As you continue to work with the report, you may find that you need to adjust the size of the controls. You can either use the sizing handles or set the Height or Width properties to change the size. Move a Control Often you need to move a control from one location to another. You can either use the move arrow to drag the control or set the Top or Left properties to change the location. Note that the value entered into the Top property is relative to the particular section. For example, you can have a text box in the Report Header section with a.25" value in the Top property and a text box in the Detail section with a.25" value in the Top property. The.25" indicates the distance from the top of that section. Change the Font Characteristics of a Control You can easily change the default font used in a label or text box using the font options in the Report Design Tools Format tab, Font group. Change the Height of a Section Many times the initial size of a section is larger or smaller than you need it to be. Additionally, as you add controls into a section or modify the sizes of various controls, you may need to adjust the height of a section. In particular, you should pay attention to the height of the detail section since that section repeats once for each record in the report. Change Formatting Properties of a Control Many modifications to a control can be made directly on the control or by setting a property of the control. However, some modifications can only be made in the Property Sheet. Recall that the specific properties vary by the type of control, but many controls share common formatting properties. Change Multiple Controls Simultaneously If you want to perform the same modification on several controls, select them all before performing the change. Use the Size/Space Button with Multiple Controls The Size/Space button allows you to set the size or the spacing of a group of controls. For example, with the Size options you can change all the controls to match the tallest or widest of the group. The Spacing options allow you to easily adjust the horizontal or vertical spacing between the controls. 18

Use the Align Button with Multiple Controls To align multiple controls to the same reference point, use the Align button. For example, if you want all of the text boxes to be aligned to the one furthest to the left, select them all and choose the alignment option. 18

SLO 6.6 Use calculations in a control on a report, create a running total in a control, and concatenate text data in a report. After completing SLO 6.6, complete Pause & Practice 6-2; assign Independent Projects 6-4 and 6-6; Improve It Project 6-7; and Challenge Projects 6-8, 6-9, and 6-10. 19

SLO 6.6 Use calculations in a control on a report, create a running total in a control, and concatenate text data in a report. A calculated control contains an expression in the Control Source property. You can use calculated controls to show the results of a mathematical equation, an aggregate function, or a text-based equation. You can use a calculated control in any report section. While there are several controls you can use as calculated controls, the most common choice is a text box. Understand and Perform Calculations Access evaluates expressions with the standard order of operations. Follow these rules when you enter an expression into a control: Enter the expression directly into the Control Source property [Property Sheet Data tab]. If you need more space to enter the expression, you can open the Expression Builder or Zoom window. Start each expression with an equals sign. Assign a name to the control in the Name property [Property Sheet Other tab]. Enclose any fields used in the expression inside square brackets []. If you include a function in the expression, such as DatePart() or UCase(), you must follow the usage rules for that function. 20

The expression is visible inside the control when the report is in Design view, and it also displays in the Control Source property if the Property Sheet is displayed. However, most expressions are longer than the size of the control. This means that you cannot read the entire expression in either the control or the property box. Any fields you use in the expression must be included in the query or table used as the record source of the report. Fields that you have added onto the report are automatically included in the record source. Occasionally, you have an expression that needs to reference a field that you don t want to display on the report. In this case, you can either edit the Record Source property and add the field into the query or you can add the field to the report but set the Visible property to No. You can place calculated controls in any section of a report. However, if you use an aggregate function in a control, the result of the calculation depends on where the control is placed. Recall that aggregate functions, such as Sum or Count, perform calculations over a group of records. An example of an expression using the Count aggregate function is =Count([ListingID]). If the control containing that formula is in a group header or group footer, the function aggregates the value of only the records that are in that group. For example, if the report is grouped by city, the Count function counts the total number of listings in each city. If the control is in a report header or report footer, the function aggregates the value of all the records in the report. In the previous example, the Count function would count the total number of listings. Do not include aggregate functions in the Page Header or Page Footer sections. If you do, an error results when you try to view the report. 20

SLO 6.6 Use calculations in a control on a report, create a running total in a control, and concatenate text data in a report. Use a Running Total A running total is a field that gets its value by accumulating a total over a set of records. You can use a running total field to show a running balance, cumulative total, or counting. A running total is not the same as an aggregate function. With a running total, a value shows for each record instead of just the overall total value at the end of a group. To create a running total, use the Running Sum property of the text box. The property has three possible values: No is the default value in this property, indicating that the text box is not a running total. Over Group accumulates the total within the same group level. When a new group starts, the value is reset. Over All accumulates the total across all of the records in the report. Set the Control Source property of the text box to the field name you wish to accumulate. If necessary, you can also enter an expression in the Control Source property. 21

Number Rows in a Report One good way to use a running total is to number the rows in a report. Concatenate Text Data Concatenation combines different parts of an expression using the & operator. In a report, you may wish to concatenate different fields to improve the way the results appear. For example, combining the first and last name, or the city, state, and ZIP code together, can produce a more readable report. A concatenated expression can combine fields from a table or query, along with constants. Include a constant, such as a specific word or punctuation mark inside quotation marks. Recall that a constant is a hard coded value. Examples of concatenation formulas include: =[FirstName] & " " & [LastName] =[City] & "," & [State] & " " & [Zip] Remember that you must include all required spacing and punctuation within the formula. For example, the & " " & part of the first formula example inserts a blank space between the first and last names while the & ", " & part of the second example formula inserts a comma and a blank space between the city and state. Potential Problems with Concatenation Formulas A common problem in writing concatenation formulas is misspelling the field names. If fields are misspelled, when you try to view the report in Layout view, Report view, or Print Preview view, an Enter Parameter Value dialog box displays. Remember that sometimes you have created a query where the dialog box should display when you run the query. However, if you are not expecting an Enter Parameter Value dialog box to display, pay attention to the name of the parameter displayed in the dialog box Hide Repeated Values Sometimes, when you view a report, you see repeated values. 21

SLO 6.7 Understand when to use a subreport, create a main report and a subreport, add a subreport onto a main report, and customize a subreport. After completing SLO 6.7, complete Pause & Practice 6-3; assign Guided Project 6-1 and Independent Project 6-5. 22

SLO 6.7 Understand when to use a subreport, create a main report and a subreport, add a subreport onto a main report, and customize a subreport. Sometimes you need to create a report that shows data from tables that have a oneto-many relationship. For example, you may want to see a report of the Placer Hills Real Estate agents that also includes some data about the agents current property listings. In this section, you learn how to use a subreport to accomplish this task. Understand Subreports A subreport is a report inserted within another report. To work correctly, there must be a relationship between the two reports. Typically, the reports represent the different sides of a one-to-many relationship. The report from the one side of the relationship is the main report, while the report from the many side of the relationship is the subreport. You create the main report and subreport as two separate reports. Then you add the subreport to the main report. Once you add the subreport, it still exists as a separate object. The main report, however, contains both the original one side fields from the main report, plus all of the many side fields on the subreport. Before you create a subreport, you need to plan the design of the finished report. Determine what tables or fields will be on the main report and what tables or fields will be on the subreport. 23

SLO 6.7 Understand when to use a subreport, create a main report and a subreport, add a subreport onto a main report, and customize a subreport. Create a Report That Includes a Subreport You can build both the main report and the subreport using any of the report tools that you have learned. Three main tasks are involved in creating a report that includes a subreport: Create the main report. Create the subreport. Add the subreport to the main report. You can build the main report and the subreport in any order, but the most common approach is to build the main report first. Customize the Main Report and Subreport After you add the subreport to the main report, you should customize the overall report so that it has a professional appearance. When you open the main report, the subreport opens automatically because the objects are now attached. This allows you to edit both objects together and create a cohesive report. Alternatively, you can open the subreport separately and edit just that object. 24

Anticipate switching back and forth frequently between Design view, Layout view, and Print Preview view as you work to edit the report. Common modifications to the report, which you already know how to do, include the following: Adjust the size and spacing of the text box and label controls. Modify font characteristics or formatting of the text boxes and label controls. Change the border property or back color property of the controls or sections. Adjust the size of the subreport or the sections on both the main report and subreport. Remove the label attached to the subreport. Adding an aggregate function to a main report with a subreport involves special considerations. You can add calculated controls to a subreport using the skills you have learned. However, if you want to use an aggregate function to calculate a value over a group of records, you need to adjust the placement of that control. Your subreport most likely does not contain a Group Header or a Group Footer section. Instead, the grouping occurs as a result of the way the subreport functions when it is attached to the main report. To use an aggregate function, place the calculation in either the Report Header or Report Footer section of the subreport. When the finished report displays, that value is calculated on each grouping in the subreport. 24

Understand action queries; create and use Update, Append, Delete, and Make Table queries. You can use action queries to make changes to the data in a database. Back up your database before running an action query because action queries make permanent changes to data and cannot be undone. An update query updates data in a database. You can add records to an existing table with an append query. A delete query deletes records from a table. You can create a new table and copy records into that table with a make table query. To ensure your action query performs as desired, first build and test it as a normal select query, and then convert it to the desired action query. Use the Query Wizard to create a crosstab query, a find duplicate records query, and a find unmatched records query. In addition to launching the Simple Query Wizard to create select queries, you can use the Query Wizard to launch the Crosstab Query Wizard, the Find Duplicates Query Wizard, and the Find Unmatched Query Wizard. A crosstab query summarizes data on two dimensions. To locate potential duplicated data in a table, create a find duplicates query. 25

An unmatched records query locates records in one table that do not have any matching records in a related table. While these types of queries can be created directly in Query Design, it is easiest to first create a query using the wizard and edit the query in Design view if needed. Use the top values property, explore and use date functions, and create a query with a subquery. Use the Top Values query property to limit the number of records that display in a query answer. Select from preset choices or enter your own value. When you use the Top Values property, you must sort the records in descending order on the desired field to retrieve the top values. Use an ascending order sort to return the lowest values. Use the available date functions in Access to perform date arithmetic, to retrieve parts of a date, such as the year, or to retrieve the name of the month or weekday of a specific date value. You can use date functions in a calculated field in a query or in a text box control on a form or report. A subquery is a query that is used inside another query. Understand report sections, build a report and add and delete fields in Design view, understand the data source of a report, and create a parameter report. The sections within a report determine where and when the contents display. A report can contain the following sections: Report Header, Report Footer, Page Header, Page Footer, Group Header, Group Footer, and Detail. Creating a report in Design view allows you the most flexibility in building the report. The Record Source property specifies which database fields are available to use in a report. Add fields to a report by selecting them from the Field List. A parameter report asks a user to enter the specific criteria value each time the report is run. Add a parameter to a report by opening the Record Source and entering the parameter in the Criteria box of the desired field. Use Design view to add a control to a report; modify the size, location, font characteristics, and formatting properties of a control; and change properties of multiple controls. In Design view, you can add controls to a report by selecting them from the Controls group on the Report Design Tools Design tab. Change the size of a control with the sizing handles or by entering a specific value in the Height or Width properties. Adjust the location of a control by dragging the control or by entering a specific value in the Top or Left properties. 25

Modify the font characteristics of a control in the Font group on the Report Design Tools Format tab or by entering a specific value in the Font Name, Font Size, Text Align, Font Weight, Font Underline, Font Italic, or Fore Color properties. Change the height of a section with the sizing handles or by entering a specific value in the Height property. Adjust the formatting properties of a control by entering the desired value in the appropriate property located on the Format tab. Change multiple controls simultaneously by selecting all of the controls and then entering the desired value in the property. Use the Align button and the Size/Space button to change the size or alignment of a group of controls. Use calculations in a control on a report, create a running total in a control, and concatenate text data in a report. A calculated control contains an expression in the Control Source property. The most common calculation control is the text box. Enter the expression by typing it directly into the Control Source property or by opening the Expression Builder or Zoom window. A running total field accumulates a total over a set of records. Create a running total by setting the Running Sum property of the text box. Select Over Group to reset the total when a new group begins. Select Over All to accumulate a total across all the records. A concatenation formula combines the contents of fields or text boxes with constants to create a more readable value. The & operator combines the different pieces. If values in a report repeat across multiple records, you can use the Hide Duplicates property to hide the repeated values. Understand when to use a subreport, create a main report and a subreport, add a subreport onto a main report, and customize a subreport. A subreport is a report inserted within another report; there must be a relationship between the two reports. The most common situation features a main report that contains fields from the one side of a one-to-many relationship and a subreport that contains fields from the many side of the relationship. Create the main report and subreport as two separate reports. Use the SubReport Wizard to add a subreport onto a main report. To use an aggregate function in a subreport, you must place the control in either the Report Header or the Report Footer sections of the subreport. 25