Saving the Inventory by Category Report to a Page
The Inventory by Category report (rptInventoryByCategory) that you created in Chapter 16, "Working with Simple
Reports
and Mailing Labels," is a candidate for conversion to a page. This report illustrates problems that you encounter with aggregate values in
group
footer sections—the
mysterious
error message shown in Figure 25.24 appears during the transformation process. It's a common practice to use text boxes with aggregate functions in report group footers, so you're likely to see this message often. Loosely translated, the error message means that RPT2DAP.xsl doesn't translate
=Sum([
FieldName
])
expressions into the required GroupOf
FieldName
function for section aggregates.
When you click OK to
acknowledge
the message, the page opens with #Name? as values of aggregate text boxes. Clicking the Expand button to display rows of the detail section opens an "Operation is not allowed when the object is closed" message (see Figure 25.25). The Category
name
is missing because pages don't display lookup field values. You can't put aggregates in the outermost footer, so there's no Grand Total value. To create a page that you can modify to
comply
with page design rules, you must delete the text box expressions and then save the modified report as a page.
Modifying the Source Query to Supply Required Field Values
For this example, substituting CategoryName and supplier CompanyName values for lookup fields requires
redesigning
the source query—qryInventory, for this example. You must also supply fields to replace the calculated Cost and Value
columns
because the page section Value aggregates depend on field values. The once-simple qryInventory query requires a total makeover. Fortunately, the required changes to the query don't affect the design of the original rptInventoryByCategory report.
|
The SQL statement for the modified qryInventory query is:
[View full width]
[View full width]
SELECT Products.ProductID, Products.ProductName, Products.
QuantityPerUnit,
Products.UnitPrice, CCur(0.667*[UnitPrice]) AS Cost, Products.
UnitsInStock,
CCur([UnitsInStock]*[Cost]) AS [Value], Categories.CategoryID,
Categories.CategoryName, Suppliers.SupplierID, Suppliers.
CompanyName
FROM Suppliers INNER JOIN (Categories
INNER JOIN Products
ON Categories.CategoryID = Products.CategoryID)
ON Suppliers.SupplierID = Products.SupplierID
WHERE (((Products.Discontinued)=False));
|
The modified qryInventory query is in the \Seua11\Chaptr25\Data25.mdb file.
|
|
Creating and Modifying the Source Report for the Page
To permit saving the sample report as a page and to simplify the page redesign process, do the following:
-
Save a copy of rptInventoryByCategory as rptInventory.
-
Open
rptInventory in Report Design view. In the Detail Section, right-click the SupplierID drop-down list and choose C
h
ange To, T
e
xt Box. Replace SupplierID with
CompanyName
as the Control Source value.
-
Delete the expression in the Cost field, and type
Cost
as the field name. Do the same for the Value text box, but type
Value
.
-
In the CategoryID footer section, change the CategoryID list to a text box, and delete the CategoryID field name. Delete the expressions in the remaining four text boxes in the CategoryID footer. All text boxes display Unbound as their value.
-
Delete the two text boxes in the Page Footer section, and move the Report Footer section up. Your redesigned source report appears as shown in Figure 25.26.
-
Change to Print Preview to check your work. Close rptInventory and save your changes.
-
Right-click rptInventory in the Database window, choose Save
A
s, and save the report as the Inventory page with Inventory.htm as the file name.
-
Click an Expand control to display the initial version of the Inventory.htm page (see Figure 25.27). Click OK to acknowledge "The DefaultSort property is invalid" message.
Removing the Navigation Controls and Adding a Category Caption
The Inventory page has only eight categories and a few products per category, so you don't need navigation controls on the form. If you retain the Header: GroupLevel0 section and the Expand controls for the group, instead of expanding all groups by default, a CategoryName caption adjacent to the Expand control aids readability.
To make the initial design changes to the page, do this:
-
Change to Page Design view. Right-click Header: GroupLevel0, and clear the Record
N
avigation check box. Do the same for the Header: qryInventory section.
-
Double-click the Expand control, click the Other tab, and change the
Src
property value to
Black Arrow
.
-
Open the Toolbox, select the Bound Span control, and draw the control adjacent to the right of the Expand control. Delete the added label.
-
Double-click the control, click the Data tab, open the
ControlSource
list, and select
CategoryName
. The
ControlSource
property value changes to
GroupOfCategoryName: CategoryName
.
-
If you want to retain the Category label and
CategoryID
text box in the Footer: GroupLevel0 section, double-click the text box and set its
ControlSource
property to
CategoryName
. In this case, the property value becomes
GroupOfCategoryName1: CategoryName
.
-
If you change the
ControlSource
property value of the
CategoryID
text box or delete it, you must change the value of the
DefaultSort
property of the
GroupLevel0
group properties. For this example, the original value is
[GroupOfCategoryID98]
ASC, but this field no longer exists in the Field List. Right-click the section, choose
G
roup Level Properties, and set the
DefaultSort
property value to
[GroupOfCategoryName] ASC
.
Tip
Be sure to change the
DefaultSort
property when deleting or changing transformed text boxes on which group sorting depends. If you don't, you receive "The DefaultSort property is invalid" messages when changing to Page view. The
DefaultSort
property value must match a GroupOf
FieldName
item in the Field List.
-
The offending
DefaultSort
property value that raises the error on expanding a group is
DESC
with no field name for GroupLevel: Query Inventory. Change
DESC
to
[Value] DESC
to fix the problem.
-
If the font name for the new controls that you've added isn't the same as the existing controls, conform the fonts in other than the Caption: GroupLevel0 section. Tahoma is the font used for most of the examples in this book.
-
Change to Page view to check your work so far (see Figure 25.28).
Adding Category Subtotals and Grand Totals to the Page
Adding subtotals and grand totals to pages
differs
considerably from the method that you use for reports. The AutoSum feature makes replacing the missing group subtotals and grand totals easy.
To replace the report's missing subtotals and grand totals, do the following:
-
Select the UnitsInStock text box in the Header: qryInventory section, and click AutoSum to add a new label and
SumOfUnitsInStock
text box in the Footer: GroupLevel0 section. Delete the label and the original text box, and drag the
SumOfUnitsInStock
text box to the right of the Sum: label.
-
Repeat step 1 for the text box under the Value label. Move the SumOfValue text box to the right of the Cat. Value label.
-
Delete the % Cat. and Value label and text boxes in the Footer: GroupLevel0 section. Programming calculated text box values is beyond the scope of this chapter. Drag the Category label and text box to the right.
-
Select the
SumOfUnitsInStock
text box, and click AutoSum to add a Footer: qryInventory-SumOfUnitsInStock section and a
SumOfSumOfUnitsInStock
text box. Delete the associated label. Align the left and right edges of the Footer section with the sections above it.
-
Repeat step 3 for the
SumOfValue
text box, and then adjust the
positions
of the text boxes under the
Units
and
Value
text boxes.
-
Select the Grand Total: label, and press Ctrl+X to cut it to the Clipboard. Delete the unnamed footer section where the Grand Total: label was located.
-
Select the Footer: qryInventory-SumOfUnitsInStock section, and press Ctrl+V to paste the label. Figure 25.29 shows the final design in Page Design view.
-
Open the report in We
b
Page Preview to display the summary version of the page (see Figure 25.30).
|
The Inventory link to the Inventory.htm page is in the Data25.mdb file located in the \Seua11\Chaptr25 folder of the
accompanying
CD-ROM.
|
|