In this report, each product is listed alphabetically. Where one letter ends, and the next begins, the starting letter is printed to assist the reader with locating their desired value. This functionality could be programmed in the report writer, but is easily implemented with just a text box control and a group.

Figure 11-12 displays the report called Alphabetical List of Products, which comes with the Northwind database example.

Figure 11-12

In Figure 11-12, notice that there is a report section called ProductName Header. This is the start of a grouping for the field called ProductName. Typically, group headers are a good place to put specific labels that may apply only on the group level. As seen here, the labels for Product Name, Category Name, and the Quantity Per Unit are displayed.

Along with those static labels is a text box. Although it looks the same as the labels, it reveals that it is a textbox by the fact that it displays a "=" sign as the first character. This is a method of populating a text box at the time of generation. So, rather than execute VBA code to populate this text box, the "=" sign instructs Access to evaluate (or calculate) the value before showing the report. The text box displays the following expression:


This expression is used to extract the first character from each Product Name (that is, Left("Apple") = "A"). Thus, every time the group header is printed, the first character is printed for each ProductName.

Now, if you're familiar with reports, at this point you may be a little confused. It would stand to reason that for every product in the table this text box should be displayed. After all, the grouping is by the ProductName. If that were the case, then the report would look like Figure 11-13.

0 0

Post a comment