Online Book Reader

Home Category

Access Cookbook - Ken Getz [61]

By Root 1988 0
and Grouping grid. Adjust the settings of each grouping field as shown in Table 3-4 for the sample report.

Table 3-4. Sorting and Grouping settings for rptPhoneBook

Setting

First Company field

Second Company field

Field/Expression

Company

Company

Sort Order

Ascending

Ascending

Group Header

Yes

No

Group Footer

No

No

Group On

Prefix Characters

Each Value

Group Interval

1

1

Keep Together

No

No

Add a text box to the header section of the grouping field. In the rptPhoneBook report, we used the property settings in Table 3-5. The completed rptPhoneBook report is shown in design view, with the Sorting and Grouping and properties sheets visible, in Figure 3-6.

Table 3-5. Property settings for rptPhoneBook

Property

Setting

Name

txtFirstLetter

ControlSource

=Left([Company],1)

Width

0.4375"

Height

0.4375"

BackColor

12632256 (grey)

ForeColor

0 (black)

FontName

Arial

FontSize

24

FontWeight

Bold

Figure 3-6. The completed rptPhoneBook report in design view

Save the report. Switch to print preview mode to preview how it will look when you print it.

Now, load 03-03.MDB. The tblCompanyAddresses table contains a list of businesses and their addresses and phone numbers. Open rptPhoneBook in preview view. This report prints the data in two snaking (newspaper-style) columns (see Figure 3-7).

Figure 3-7. The two-column rptPhoneBook report

Discussion


When you create a report, Access assumes you want only one column unless you specify otherwise. If you want more than one column, you must adjust the layout properties of the page using the Columns tab of the Page Setup dialog. The key settings are Number of Columns, Column Spacing (the extra margin between columns), Width (the width of each column), and Column Layout (whether Access first prints an entire column or an entire row). If you want to produce snaking-column (newspaper-style) reports, select "Down, then Across" for Column Layout; for mailing-label-type reports, choose "Across, then Down". For most purposes, you can ignore the other settings.

You will usually create groups in reports that break on the value of a field itself. For example, grouping on Company will trigger a new group for each new unique value of the Company field. Access, however, includes two group properties that allow you to alter the frequency of groupings: GroupOn and GroupInterval. Depending on the data type of the grouping field (see Table 3-6), you can use GroupOn to group on some subset of characters (Text), a range of numbers (Number, Currency), or a period of time (Date/Time). Using the GroupInterval property, you can adjust the grouping further—for example, you could break on the first two characters of a name, every $10, or every two months.

Table 3-6. GroupOn property choices

Data type of field

GroupOn choices

Text

Each Value (default)Prefix Characters

Number, Currency

Each Value (default)Interval

Date/Time

Each Value (default)YearQtrMonthWeekDayHourMinute

When you use the GroupOn property to group on anything other than Each Value, you must realize that the records within the groupings will not be sorted. This means that in most cases you'll also need to include a second sorted copy of the field with GroupOn set to Each Value. This is what we did in the rptPhoneBook example.

SORTING OR GROUPING?

When you add a field or expression to the Sorting and Grouping window, you may wonder what determines whether a field is a group or merely a sort. No single property determines this—rather, a field becomes a group field if you set either GroupHeader or GroupFooter (or both) to Yes. You can convert an existing group field to a sort field by setting both of these properties to No.

There are several section, report, and group properties that you can adjust to control whether a group is kept together on the same column or page and whether a new column or page is started before or after a group.

See Also


See the Solution in Recipe 3.14 for more details on controlling page and

Return Main Page Previous Page Next Page

®Online Book Reader