Week 7 - What We'll Be Working on This Week
In Access there is a lot more to queries than just creating Select queries that apply filters to the data in tables and other queries. It is possible to perform calculations in queries as a means of deriving new data from existing fields, and to summarize data using Aggregate functions. Crosstab queries, which are similar to Pivot Tables in Microsoft Excel, will save you hours of work in terms of summarizing table data, as well. In addition, Access provides a number of Special Purpose queries:
Parameter queries will enable the user to specify criteria for the query when the query is run
AutoLookup queries will enable you to enter one field value into the Datasheet View of the
query and have Access automatically look up and enter other values into the current record.
Action queries will cause changes to be made to an object when the query is run:
o Update, Append, Delete and Make-Table queries will all potentially save you a
tremendous amount of time and make life very, very sweet.
Goals:
Creating a calculation field in a query page 3
Concatenating fields in a query page 6
Summarizing with Aggregate functions page 9
Adding other functions to the Aggregate Summary page 11
Adding Captions page 13
Creating a Crosstab query page 15
Creating a Parameter query page 20
Creating a Parameter query for a range of dates page 23
Creating an AutoLookup query page 26
Observing the impact of the AutoLookup query on the table page 28
Documenting the database page 32
Creating an Update query page 38
Creating an Append query page 44
Creating a Delete query page 48
Creating a Make-Table query page 50
This is where we're headed this week. So let's get to it!
2
Goals for this section:
Creating a calculation field in a query
Concatenating fields in a query
Summarizing with Aggregate functions
Adding other functions to the Aggregate Summary
Adding Captions
Creating a Crosstab query
Calculated Data Type
Before we discuss setting up calculations in a query, I want to discuss the new Calculated data type that first appeared in Access 2010 (which some of you used in your last assignment). With the calculated data type, you can now store a formula or expression that will be updated automatically when the components of the expression change. The disadvantage of defining a field in a table as a Calculated data type is that the calculation can only use fields in that table. The advantage of using a Calculated data type is that it short cuts doing calculations. By putting the calculation in the table, you do not have to repeat the calculation where ever it is needed. All you do is just add the field to the form, report or query and it is done for you. Using a query to perform calculations helps to avoid the 'bulking up' of your table with unnecessary information. A query calculates the information whenever you need it. I strongly recommend that you put your calculations in your queries rather than tables as this allows for greater flexibility in your data design.
Performing Calculations in a Query
If you need to calculate any of the fields in your database tables, don't do it on a calculator and enter the results into the table manually, and don't export the data to Excel in order to get your answers. Instead, create a query, include the Number or Currency fields to be calculated, and create a formula in a blank column of the QBE Design grid. Calculation results may be based on any available fields in any of the objects on