Creating Calculated Fields in Access Queries and Reports



Similar documents
Steps to Create a Database


Basic Pivot Tables. To begin your pivot table, choose Data, Pivot Table and Pivot Chart Report. 1 of 18

Microsoft Access 2010 handout

REDUCING YOUR MICROSOFT OUTLOOK MAILBOX SIZE

Using Microsoft Access

Getting Started with Excel Table of Contents

MICROSOFT ACCESS STEP BY STEP GUIDE

MICROSOFT ACCESS 2007 BOOK 2

Introduction to Microsoft Access 2003

Using Microsoft Access

Introduction to Microsoft Access 2010

Step Sheet: Creating a Data Table and Charts

How To Insert Hyperlinks In Powerpoint Powerpoint

Creating forms in Microsoft Access 2007

Introduction. Inserting Hyperlinks. PowerPoint 2010 Hyperlinks and Action Buttons. About Hyperlinks. Page 1

How to Edit an . Here are some of the things you can do to customize your

Managing Contacts in Outlook

Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint

Creating a Form. A form is something that is created allowing users to enter information in a more visual manner than a datasheet view.

Page Numbering for a Thesis or Dissertation

Introduction to Microsoft Access 2013

Crystal Reports Payroll Exercise

Microsoft PowerPoint 2008

LETTERS, LABELS &

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Instructions for Creating Silly Survey Database

Double-click an appointment to view the details.

Access 2007 Creating Forms Table of Contents

How to make a line graph using Excel 2007

Microsoft Excel 2010 Tutorial

Utilizing Microsoft Access Forms and Reports

Analyzing Excel Data Using Pivot Tables

MICROSOFT ACCESS 2003 TUTORIAL

HOW TO ORGANIZE PICTURES

Microsoft Access GUI Building

Sage Accountants Business Cloud EasyEditor Quick Start Guide

Using an Access Database

Excel 2007 Basic knowledge

If you know exactly how you want your business forms to look and don t mind detail

Microsoft Excel 2007 Consolidate Data & Analyze with Pivot Table Windows XP

Introduction to MS WINDOWS XP

Creating Basic HTML Forms in Microsoft FrontPage

History Explorer. View and Export Logged Print Job Information WHITE PAPER

Basic Excel Handbook

Intellect Platform - Tables and Templates Basic Document Management System - A101

In this example, Mrs. Smith is looking to create graphs that represent the ethnic diversity of the 24 students in her 4 th grade class.

Microsoft Word Track Changes

Personal Portfolios on Blackboard

Databases in Microsoft Access David M. Marcovitz, Ph.D.

Creating a Database in Access

Microsoft PowerPoint 2010 Handout

PA Payroll Exercise for Intermediate Excel

Weebly.com First Steps

QUICK START GUIDE

Introduction to. Microsoft Access Practicals

Knowledgebase Article

Creating QBE Queries in Microsoft SQL Server

Microsoft Access Creating Filters and Tables

Microsoft Word Tips and Tricks

User Services. Microsoft Access 2003 II. Use the new Microsoft

This activity will show you how to draw graphs of algebraic functions in Excel.

BID2WIN Workshop. Advanced Report Writing

Styles, Tables of Contents, and Tables of Authorities in Microsoft Word 2010

Getting Started on the Computer With Mouseaerobics! Windows XP

MICROSOFT ACCESS A. CREATING A DATABASE B. CREATING TABLES IN A DATABASE

BusinessObjects: General Report Writing for Version 5

Mac Outlook Calendar/Scheduler and Tasks

Spreadsheet - Introduction

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

2. Building Cross-Tabs in Your Reports Create a Cross-Tab Create a Specified Group Order Filter Cross-Tab by Group Keep Groups Together

Mail Merge Tutorial (for Word ) By Allison King Spring 2007 (updated Fall 2007)

Presentations and PowerPoint

Excel 2003 Tutorial I

Outlook . User Guide IS TRAINING CENTER. 833 Chestnut St, Suite 600. Philadelphia, PA

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

Web Intelligence User Guide

Microsoft Access 2000

Don't have Outlook? Download and configure the Microsoft Office Suite (which includes Outlook)!

MICROSOFT OUTLOOK 2010 WORK WITH CONTACTS

Microsoft Excel Tips & Tricks

Creating a Database using Access 2007

Access Database Design

Training Guide. Managing Your Reminders and Contact History in Contact Manager

Developing Own Crystal Reports

Creating a Newsletter with Microsoft Word

Instructions for Formatting MLA Style Papers in Microsoft Word 2010

Microsoft Office Access 2007 Basics

Access 2010 Intermediate Skills

Acrobat PDF Forms - Part 2

Chapter 14: Links. Types of Links. 1 Chapter 14: Links

Software Application Tutorial

Publisher 2010 Create an Event Flyer

Using the Cute Rich-Text Editor

INTRODUCTION TO MICROSOFT ACCESS Tables, Queries, Forms & Reports

Computer Science 125. Microsoft Access Project

Publisher 2007: Part 2 Advanced Features. Grouped Objects in Publisher:

Chapter 4: Website Basics

Transcription:

Creating Calculated Fields in Access Queries and Reports Access 2000 has a tool called the Expression Builder that makes it relatively easy to create new fields that calculate other existing numeric fields in your database. For example, if you have existing fields called Sales in 1999 and Sales in 2000, you can add the two together in a query or a report using the Expression Builder. Using Expression Builder in Queries First, get into the QBE (design view) of a new query as you normally would. For this example, we will use a database for a fictitious "dog-sitting" parlor. The database contains the dog's name, owner's first and last name, breed of the dog, and the amount paid so far this fiscal year and the amount outstanding. For this query, we will display the owner's last name, owner's first name, amount paid, and amount outstanding, and then a calculated field that adds the last two together. To create a new field that adds the amount paid to the amount outstanding, place your cursor in the next column to the right, then click on the icon that looks like the magic wand on the Access toolbar:. This will open up a dialog box called the Expression Builder: Basically, you want to double-click on the item you want to build the expression from within the far left window (in this case, an Access table) to reveal a list of all fields in that table in the middle window. Since we want to add two fields together from an Access table, double-click on the Tables folder in the left window to reveal a list of all tables in the database. In this case, we just have one table, called Dog Owners. Double-click on the Dog Owners table name, to show a list of all fields in that table. When done, the Expression Builder should look like this:

2 Notice underneath the Expression Builder's main window are various buttons for adding, subtracting, multiplying, etc. We want to add together the Amount Paid this FY to the Amount Outstanding. Therefore, we first double-click on the field named Amount Paid this FY, so that it appears in the Expression Builder window: The Expression Builder window displays field names by first giving the table name (in this case, Dog Owners) followed by an exclamation point and the specific field name from within that table.

3 Next, it is a matter of building our formula by clicking on the plus sign button, and finally double-clicking on the field name we want to add to our formula--namely, the Amount Outstanding field. When completed, our Expression Builder window should look like this: Before clicking OK, though, there's one more step. We need to create a field name for our newly invented Access query. If we don't, it will have the rather nondescript name of Expr1 on our query. So, to insert a field name, click just before everything else in the Expression Builder window, and type a field name of your choice, followed by a colon. In this case, we'll call it Total Transactions. Here's what the Expression Builder window now looks like: Careful with your spacing when typing anything in manually in this window! Be sure not to accidentally delete any brackets for the table/field names.

4 Now, when we click OK, our new field will be displayed in the QBE window, so that is looks like what we see below. Also, when we actually run the query, it will appear as a column with the correct name. Best of all, when we save this query, this newly created field can appear on any future Access reports we do. Using Expression Builder in Reports We can use a similar method when creating a field in an Access report. In this case, let's display the Average Total Transactions for everyone in our database on a report, using the new field we just used in our previous query. We can create our initial report using the query we already saved by using the Report Wizard in Access. When creating the report, we make sure to specify a Grouping Level, using Breeds as the grouping. This is necessary (as explained on the Using Access 2000 handout) if we want to have summary data such as averages, totals, etc., appear for various fields on our report. But even after clicking the Summary Options button during the report creation and specifying Average for our Total Transactions field, it will only display the average within each grouping level (in this case, breed), and NOT for the entire database. Note, for example, the second page of our report after creating it with the Report Wizard, using our previously created query that included a new field called Total Transactions:

5 Our newly created average field does not display in the currency format ($), but that is easily solved, and is explained at the end of this handout. The average is displayed within each grouping (dog breed), but not for all records as a whole in the database. Notice average appears within each grouping (dog breed), but not for all records as a whole. Notice on the report above the average (Avg) is displayed at the end of each breed in the "Summary for Breed" section of the report, but there is no average shown at the bottom of the report for all clients, averaged together. To do this, we have to create a new text box on the Report it the design view, and build an expression. So first, with the report preview on the screen, we click the Design View button on the toolbar:. The new field we want to add should be at the bottom of the report, so we have to add it in the section called Report Footer. Make sure you have the toolbox in the design view (click View pull-down menu, then Toolbox if you don't), then click on the Text Box icon (the lower case ab letters in the toolbox) and click and drag a small rectangle in the Report Footer section. (Don't worry that the Report Footer section is gray--it won't be once you create the boxes.) Notice that when you select the Text Box icon in the toolbox that both a label and a box are created. Here is what our report now looks like in design view: To create both a label and a text box in the report design view, click on this icon in the Toolbox....... then create a new label and box in the Report Footer section by clicking and dragging in this area.

6 To get the easy part out of the way first and change the label, just click in the box labeled Text21 in bold face type, and type in the label that will appear in this report. We'll call it Average Total Transactions. Here's what it will look like after typing it, and after we re-size the text box a little bit and move it out of the way: To move a box in the design view of Access, make sure the mouse pointer first looks like a pointing finger near the square-shaped icon in the corner (as shown), then click and drag it. Now, we have to do something about the newly created text box that says Unbound in our report. We want it to show the average of all Total Transactions. First, select the box with the mouse, and click the View pull-down menu, then Properties. (Alternatively, right-click in the box, then select Properties from the resulting menu.) The Properties dialog box should come up, as shown below. Make sure the Properties dialog box title bar shows Text Box at the top of it, or else you may be editing the wrong box! Next, with either the All tab or the Data tab enabled at the top of this box, click your mouse in the window labeled Control Source so that a little box with three dots appears next to it: Make sure you're in the right text box, and also that you're not editing a label! This is the button you will be clicking to bring up the Expression Builder After clicking that three-dotted box, it will bring up the Expression Builder window. Unlike last time with our query, however, we'll have to do things a little differently in the Expression Builder. Because averaging a field is considered a function (similar to the Average function within Excel), this time we want to double-click in the left-side window of the Expression Builder to select the Functions folder label, and then the folder that appears underneath that called Built-In-Functions. This will bring up the following window:

7 After double-clicking on the Functions folder, then the Built-In Functions folder on the far left, you'll see a listing of functions arranged by type of function (the middle window), and the name of the function on the far right. If you've ever created a function in Excel this dialog box looks somewhat similar. At this point, it's similar to creating a function within Excel--the function name appears followed by parentheses, with the parentheses containing the item(s) we want the function to act upon. You can spot the function name we want in the window on the far right--it's called Avg. Double click on it to see the following: Now, we need to select the field we wish to average. Notice that in the window above the function name Avg is followed by: (<<expr>>). We want to place our field name within those parentheses. The quickest way to do this is double-click within the parentheses so that the text within them is selected:

8 Next, leaving that text in the window selected, double-click on the folder name in the left window that contains the field we want to average. In this case, it will be in the Queries folder, since the Total Transactions field is one that was created for a query. After double-clicking on the Queries folder, double-click on the query name (the name you saved your query under): Select the field you wish to average from the middle window, then double-click on it. If everything worked, your field name will appear within the parentheses after the function name. Double-click on the query name on the left to reveal a list of all fields used in that query in the middle window.

9 Finally, double click on the field within the query that is listed in the middle window. Here is what the end result should look like: Notice the field name is now correctly within the parentheses after the function name. After clicking OK you will be back in the design view of the report at the Properties window. Close the Properties window, and your report design should now reflect your newly created field: Report design view now shows our new function. Click the Print Preview button to see if everything looks okay. Advance the "page" until you get to the last page of the report (remember, we did this in the Report Footer section in the design view--which means at the bottom of the Report):

10 Here is our newly created label and text box in the report. Notice, however, that our new field is not properly formatted in the currency format. (Neither, for that matter, are the other average figures we put in the report based on our earlier query). Fortunately, that's easily solved by going back into design view, clicking in the proper text box and going back to the Properties box as discussed earlier. In the Properties dialog box, click on the Format tab, then click on the drop-down arrow that appears next to the Format window. Here, you just click Currency, and that will take care of it: Click here in the Properties box to ensure that your field is displaying in the format you want it to. Be sure to do this both for our newly created field in the Report and also within the Detail section of the Report in the design view to have the average field display as currency. Created November 2000 for CIS 120 - K. Black