Lesson 10-11
Lesson 10-11
Lesson 10-11
Modifying queries
Access offers several options for making your queries work better for you. In addition to
modifying your query criteria and joins after you build them, you can choose to sort and
hide fields in your query results.
In the bottom-right corner of your Access window, locate the small view icons.
Click the Design View icon, which is the icon farthest to the right.
Once in Design view, make the desired changes, then select the Run command to view
your updated results.
Sorting queries
Access allows you to apply multiple sorts simultaneously while designing your query.
This allows you to view your data exactly the way you want.
A sort that includes more than one sorted field is called a multilevel sort. A multilevel
sort allows you to apply an initial sort, then further organize data with additional
sorts. For instance, if you had a table filled with customers and their addresses, you
might choose to first sort the records by city, then alphabetically by last name.
When more than one sort is included in a query, Access reads the sorts from left to
right. This means the leftmost sort will be applied first. In the example below,
customers will be sorted first by the City where they live and then by the Zip Code
within that city.
3. Repeat the process in the other fields to add additional sorts. Remember, the
sorts are applied from left to right, so any additional sorts must be applied to
fields located to the right of your primary sort. If necessary, you can rearrange
the fields by clicking the top of a field and dragging it to a new location.
4. To apply the sort, click the Run command.
You can also apply multilevel sorts to tables that don't have queries applied to
them. On the Home tab on the Ribbon, select the Advanced drop-down
command in the Sort & Filter group. From the menu that appears, select
Advanced Filter/Sort and create the multilevel sort as you normally would. When
you're finished, click the Toggle Filter command to apply your sort.
However, we really didn't need to see this information in our final query results. In fact, if
we were just looking for customer names and addresses, seeing the order number
mixed in there might have been distracting. Fortunately, Access makes it easy to hide
fields while still including any criteria they contain.
4. To see the updated query, select the Run command. The field will be hidden.
To unhide a hidden field, simply return to Design view and click the checkbox in
the field's Show: row again.
Totals queries
Sometimes setting simple criteria won't give you the results you need, especially when
you're working with numerical values. You may want to see your query results grouped
or counted in some way. For example, let's say we want to find out how many of each
menu item at our bakery has been ordered—how many Almond Croissants, Apple Pies,
and so on. To do this, we could create a totals query to find the sum of the quantities for
each item.
First, the totals query will group all similar menu items from separate orders (for
example, Almond Croissants). Then, the Sum function will add the values in the
Quantity field to calculate the total number sold for that item.
The Sum function helped us find the desired information in this example, but in other
situations you may need to use a different function to find the answer you need. There
are several functions you can choose from:
Count: Counts the total number of each item
3. A row will be added to the table in the design grid, with all values in that row set
to Group By. Select the cell in the Total: row of the field you want to perform a
calculation on, then click the drop-down arrow that appears.
4. Select the calculation you want to be performed in that field. In our example, we
want to add the quantities of products we've sold, so we'll select the Sum option.
5. When you are satisfied with your query design, select the Run command on the
Query Tools Design tab to run the query.
6. The query results will be displayed in the query's Datasheet view, which looks
like a table. If you want, save your query by clicking the Save command on the
Quick Access Toolbar.
2. Select the Create tab on the Ribbon. Locate the Reports group, then click the
Report command.
Just like tables and queries, reports can be sorted and filtered. Simply right-click the field
you want to sort or filter, then select the desired option from the menu.
Deleting fields
You might find that your report contains some fields you don't really need to view. For
instance, our report contains the Zip Code field, which isn't necessary in a list of orders.
Fortunately, you can delete fields in reports without affecting the table or query where
you grabbed your data.
When you delete a field, be sure to delete its header as well. Simply select the header and press
the Delete key.
Printing and saving reports in Print Preview
While you can print reports using commands in Backstage view, you can also use Print
Preview. Print Preview shows you how your report will appear on the printed page. It
also allows you to modify the way your report is displayed, print it, and even save it as a
different file type.
To print a report:
1. From the Home tab, click the View command, then select Print Preview from the
drop-down list. Your report will be shown as it will appear on the printed page.
2. If necessary, modify the page size, margin width, and page orientation using the
related commands on the Ribbon.
4. The Print dialog box will appear. Set any desired print options, then click OK. The
report will be printed.
Saving reports
You can save reports in other formats so they'll be viewable outside of Access. This is
called exporting a file, and it allows you to view and even modify reports in other formats
and programs.
Access offers options to save your report as an Excel file, text file, PDF, and HTML
document, among other file types. Experiment with the different export options to find
the one that best suits your needs.
To export a report:
1. From the Home tab, click the View command, then select Print Preview from the
drop-down list.
2. Locate the Data group on the Ribbon.
3. Select one of the file type options, or click More to see options to save your
report as a Word or HTML file.
4. A dialog box will appear. Select the location where you want to save the report.
5. Enter a file name for the report, then click Publish.
6. A dialog box will appear to notify you that your file has been successfully saved.
Click Close to return to your report.
Some export options will cause the Export Wizard to appear. Simply follow the
instructions to export your report.