11 Designing Advanced
Reports
In the previous chapter, you learned to create simple reports—nicely formatted printouts that arrange information inside a single table. Simple reports are a great way to create a hard copy that has more polish than a datasheet printout.
As you learned in the previous chapter, simple reports give you the fine-grained for- matting you need to highlight important columns and values, and they handle long text fields gracefully, without wasting space or chopping off part of the data.
Simple reports are a great Access tool, but they’re still, well, simple. Their structure is their main limitation. No matter how you format or arrange your data in a simple report, Access always presents it as a table. In the real world, you may want your printed data to take other forms. You may want to transform your data into cus- tomer invoices, class attendance lists, or mailing labels. All these reports perform the same task—they take the data in a table, and then arrange it on the printed page—but none of them can be satisfied with a plain-vanilla report and its simple tabular structure.
In this chapter, you’ll see how to create a variety of more specialized reports that take the concepts you learned in the last chapter, and extend them with a few new tricks.
Along the way, you’ll take a look at Design view, you’ll learn how to add pictures and shapes, and you’ll tell Access where it can break pages in long printouts. You’ll also see how to use grouping to analyze data and calculate subtotals.
Improving Reports in Design View
Design view is the secret to setting your reports free. As you learned in the previ- ous chapter, Design view is another way of looking at your report. Unlike in Layout view, in Design view you don’t see any report data. Instead, you see a blueprint that
Improving Reports in Design View
tells Access how to create the report. Using this blueprint, you can do things that just aren’t possible in any other view.
Consider the simple report with the list of products that you created in the previ- ous chapter. If you switch to Design view, then you see what makes this report tick (Figure 11-1). To get to Design view, right-click the tab title, and then choose Design view.
Figure 11-1:
The Design view win- dow is divided into five sections. Each section tells Access how to con- struct part of the report.
The Detail section is the most important part.
When you fire up the report (by printing it or viewing it in Layout mode), Access repeats the Detail section once for each row. It fills in the boxes in the Detail view with the values from the corresponding record.
Goes at the top of the report Goes at the top of each page Appears once for each record Goes at the bottom of each page
Goes at the bottom of the report
Note: The odd grid of lines and dots you see in Design view is intended to help you line up different parts of your report when you aren’t using a layout table. As you’ll see, it’s often important to place report elements in precise positions when using Design view.
The Design View Sections
The secret to mastering Design view is understanding its five different sections. Al- though you can leave some sections blank, every report includes them in exactly the same order:
• Report Header. This section appears once at the beginning of your report, on the first page. This section is where you add titles, logos, and your own personal byline.
• Page Header. This section appears just under the report header on the first page, and at the top of each subsequent page. It’s the place to add page numbers, and you can also use it for column headers in simple, tabular reports like the product catalog.
• Detail. This section appears once immediately after the page header, and it’s the heart of all reports. The trick is that the Detail section is repeated once for each re- cord in your report. In a simple tabular report, this section represents a single row.
• Page Footer. This section appears at the bottom of each page. If you don’t use the page header for page numbers, then this section provides your other option.
• Report Footer. This section appears once at the very end of the report. You can use it to print summary information, copyright statements, the date of printing, and other miscellanea.
The content in these sections looks a fair bit different from what you see in other views, because Design view doesn’t show the live data. Instead, it includes placehold- ers where Access can insert the necessary information each time it runs the report.
When you run the product report, Access grabs the values from the ProductCategory- ID, ProductName, Price, and Description fields and then shuffles them into the matching boxes.
You’ll need a bit of time before you’re comfortable manipulating the content in De- sign view. First, you need to learn that you can adjust each section’s size. This ability makes sense, because different reports allocate different amounts of space to each region. Figure 11-2 shows how this works.
Figure 11-2: To resize a section, move your mouse to the border just underneath the section you want to change. Drag the border down (to add more space) or up (to remove space). It’s then up to you to shuffle around the content in- side to fit the available space. In this example, the Detail section is being heightened.
Click and drag here to resize the Detail section
Tip: If you don’t want to use a section, then you can resize it almost out of existence. Look at the report footer section in Figure 11-1. It’s there, but vanishingly small, because this report doesn’t use the footer.
Alternatively, you can delete the header and footer section. Just right-click the report surface (in Design view), and then choose Page Header/Footer to remove the page header and page footer sections, or Report Header/Footer to remove the report header and footer sections. Click these commands again to make these sections reappear, but without any content (you need to fill that in yourself).
Improving Reports in Design View
Understanding Controls
Design view gives you a different perspective for your report. Access represents ev- erything in your report with controls: graphical widgets that have text, pictures, and formatting. Each control is a distinct element. You can change what it looks like, or you can drag it to a different position (although you may need to pull it out of its layout table first, as described on page 335).
Figure 11-3 points out the controls in the product catalog report. You don’t see all the controls, because not all the columns fit into view at once.
Figure 11-3:
In the product report, you’ll find controls for the title, page number infor- mation, column headers, and data. Each control has a thin black border around it, which helps you spot it and resize it in Design view. These borders won’t appear in the printout.
Image control
Label control Partly visible Text Box controls
A row of Label controls Combo Box control
Text Box controls
Note: Something may strike you as a little odd in Figure 11-3. Namely, several text box controls look more like label controls. As you’ll learn later in this chapter, reports use label controls for text that never changes and use text box controls for text that does (based on the current date, the current record, the current page, and so on).
To get a little more comfortable in Design view, play around with a simple report. (If you don’t have a report handy, then you can download the Boutique Fudge database with the examples for this chapter; see the Missing CD page at www.missingmanuals.
com/cds.) Here are some tasks to try out:
• Drag the controls in the report header and page footer sections from one place to another.
• Change the size of a control in the report header or page footer section by drag- ging the black border that appears around it.
• Rearrange the columns by dragging the column headers around the page head- er section, or by dragging the fields around the Detail section. When you move a column, Access automatically arranges the other columns around it. Access works the same way when you rearrange the columns in Layout view.
• Select a control, and then change its formatting using the ribbon’s Report De- sign Tools | Format➝Font section. This method works with the elements in the page header and footer sections as well as the column headers and individual fields.
When you’re finished making a change, right-click the tab title, and then choose an- other view (like Report view, Layout view, or Print Preview) to see what your printed report will look like. When you close your report, Access prompts you to save the changes you’ve made.
You should be able to do everything you did to customize a report in Layout view using Design view. Of course, Layout view is easier to use for most of these tasks. But as you’ll see in the following section, Design view gives you more freedom to break out of the typical report table and arrange your data however you want.
Moving Fields Out of a Layout
In a simple report, Access groups all the fields into something called a layout. The layout is actually a specialized container that lets you easily work with groups of fields. It provides several indispensable conveniences that you saw in Chapter 10:
• When you move a column to a new position, Access rearranges all the other columns accordingly.
• When you widen a column, Access bumps all the following columns out of the way. Similarly, when you shrink a column, the following columns move to fill the extra space.
Without a layout, you couldn’t move your columns around as quickly. Every time you wanted to make a change in one column, you’d need to painstakingly reposition every other column. In a report with several dozen fields, this process adds up to a major headache.
Although layouts are small miracles of convenience, they’re also a bit of a straitjacket if you want to arrange your data differently. Suppose you want to take the product catalog report and make it look less like an inventory list and more like a retail pub- lication, as shown in Figure 11-4. You can’t do this with a layout, because your fields are always locked into a tight tabular structure. You can only get this result if you take your fields out of their layout table, and then arrange them by hand.
Note: Don’t get confused between layouts and Layout view. A layout is a container that arranges a bunch of controls. Layout view is a way to look at your report and change various aspects of it. You can use Layout view even if you don’t use any layout containers.
Improving Reports in Design View
Figure 11-4:
This version of the product catalog report doesn’t use a layout table—instead, all the controls are free-floating. Access still creates the report in the same way as it does when you use a layout table—it repeats the Detail section once for each row. The only difference is the way Access arranges information in the Detail section.
In the following steps, you’ll learn how to transform the layout-based product cata- log into the table-free version shown in Figure 11-4. You’ll begin in Layout view, where you can remove the fields from their layout. Then you’ll switch into Design view to customize the arrangement of your fields. (Word of advice: Once you know your way around Design view, you’ll probably get the job done quicker by creating a new, layout-free report from scratch in Design view, as described on page 340.)
1. Switch to Layout view (right-click the tab title, and then choose Layout View).
You can remove fields in Design view, but the results aren’t as pleasant. When you remove a field from a layout in Layout view, Access automatically bumps it aside and gives it a little space of its own. But when you remove a field in Design view, Access leaves it in its original position. You end up with controls that are bunched up on top of each other, which makes them very difficult to arrange.
2. Select the entire table.
It’s neater and easier to remove all of a layout’s fields at once than to remove them one by one. To liberate the entire report at once, click any value in your report; a tiny four-way-arrow icon appears next to the top-left corner of your layout table. Click that icon to select the entire table.
3. Right-click the now-selected table and choose Layout➝Remove Layout.
The Layout submenu provides three choices:
• Tabular puts fields into a column-based arrangement, which is what you already have.
• Stacked puts fields one on top of the other, which takes up more space but is nicer for certain types of data (for example, tables with just a few fields that contain a lot of text).
• Remove Layout, the final option, puts the control in your hand, letting you create any arrangement you can imagine.
4. Right-click the tab title, and then choose Design view.
You could arrange your fields in Layout view, but most people find this tricky because Layout view shows several records at a time. Instead, you’ll probably have an easier time arranging them using the section templates in Design view.
5. Make the Detail section larger by dragging down the bottom edge (as shown in Figure 11-2).
In a simple report, you need exactly one row to fit your record. But when you create a custom arrangement, you almost always need more space.
6. Drag the text box control for each field to the right place in the Detail section, and then resize it to the right size.
It may take some rearranging before you finally get all the boxes in the right places. Since the information isn’t in a layout table anymore, Access doesn’t automatically move information out of the way. Instead, you need to arrange everything by hand and make sure no two fields overlap.
7. In the Page Header section, select a column header for one of the fields in the Detail section. Either press Delete to remove it, or drag it down into the Detail section.
It makes no sense to include a column header at the top of a page when your field isn’t a part of the table any longer. If the data is fairly self-explanatory, you don’t need a caption at all. However, you could also drag the column header into the Detail section, and place it next to the corresponding data, so that it acts like a caption. The report in Figure 11-4 keeps the captions for the UnitsInStock and UnitsOnOrder fields.
8. If you haven’t already, select each field, and then apply the formatting you want.
You can format the data in Design view in much the same way you do in Lay- out view. Just select the field, and then use the ribbon’s Report Design Tools | Format➝Font section. Hold down Shift if you want to select (and then format) several controls at a time.
When you’re finished, switch to Layout view or Report view to see the result of your changes. Figure 11-5 shows the final arrangement for the revamped prod- uct catalog report shown in Figure 11-4.
Improving Reports in Design View
Figure 11-5:
Once you’ve removed the fields from their layout table, you can arrange them any way you want—even letting one control overlap another for a tighter display.
Adding More Controls
In the previous example, you used your knowledge of controls to unshackle the fields in your report. However, text boxes with field values aren’t the only type of control you can use. Access reports also support labels, pictures, buttons, and other graphical gizmos that can jazz up the dullest report. Some of the reasons you may add more controls include:
• To add more text information, like subtitles, disclaimers, explanatory notes, the company name, and so on.
• To draw separating lines between regions in the Detail section.
• To draw additional borders around important content.
• To pop a logo into the header or footer. (The automatic logos you learned about on page 303 are limited to the report header.)
You can easily add a few more controls to your report. Just find the right button on the ribbon. When your report is in Design view, you’ll find one-stop shopping in the Report Design Tools | Design tab, as shown in Figure 11-6.
Some of these controls—like text boxes, checkboxes, and other editing controls—are really intended for use in forms and aren’t much use in a report. Others, like buttons and hyperlinks, can trigger useful actions when combined with a dash of macro code (as you’ll see in Chapter 15). But right now, you’ll want to use only a few controls:
• The label control holds small or large amounts of fixed text. For example, all the column headers with the field names are labels.
• The text box control holds a dynamic expression—in other words, text that can change.
• The image control holds a picture.
• The line control lets you draw vertical, horizontal, and even diagonal lines. It’s handy when you want to separate content graphically, and borders alone don’t give you the effect you want.
• The rectangle control lets you draw formatted rectangles around other controls to help content stand out.
• The page break control lets you split the Detail section into separate pages—
exactly where you want. It’s useful when there’s a large amount of information in the Detail section, or when you’re printing forms that need to wind up on separate pages (like invoices for different customers).
Figure 11-6:
The buttons in the Controls section let you add all sorts of useful widgets to your reports. To add one of these controls, click the button, and then draw the control onto the design surface at the desired location. Using the buttons to the right of the Controls section, you can add a few more ingredients to each page of your report, like a report title and page numbers. When you click one of these buttons, Ac- cess automatically inserts the corresponding element where it belongs.
Buttons for adding controls
Click here to open a drop-down panel that shows all the controls at once Click here to scroll through
the list of controls
Buttons for adding a logo, a title, page numbers,
or a date
Note: Although Access has controls for pictures, rectangles, and lines, it doesn’t have the Clip Art features you find in other Office applications. So don’t look around for fancy shapes and word art—you won’t find them.
Once you’ve picked the control you want, you can add it your report, as shown in Figure 11-7.