The Section Expert

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 8 - Customizing Sections
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

The Section Expert, shown in Figure 8.7, is used to customize the behavior of sections beyond what is accessible through the pop-up section submenu. To open the Section Expert, choose that option from the pop-up submenu shown previously in Figure 8.4 or choose Report > Section Expert.

click to expand
Figure 8.7. Section Expert

The left side of the Section Expert lists all sections currently in the report. Here we have the standard set of five plus Group Header and Group Footer sections. Along the top edge of the list of sections are five action buttons:

Insert You can add a new section below the currently selected section. The type of section (Group Header, Page Header, Details, etc.) is based on the type of the currently selected section. For example, if the Details section is highlighted and you click the Insert button, a new Details section is added after the current Details section. The Section Expert adds the new section and assigns a new alphabet character to it in ascending order. Figure 8.8 shows that a new Group Header section was inserted as well as a new Details section. The Group Header #1 now consists of two components: Group Header #1a and Group Header #1b. #1a is the original and #1b is the one that was added. At this point, you can no longer configure Group Header #1 as it is just a title that contains the other two; it is the two subcomponents that can be configured. You can do things like move #1a below #1b and Crystal will automatically renumber them.


Figure 8.8. Inserting sections with the Section Expert

When adding sections, they do not have to be added in balanced pairs. Above, only a Group Header was added; no Group Footer was added. In Design mode, shown in Figure 8.9, the effect is a blank section added below the original section.


Figure 8.9. New sections in Design mode

Tip 

New sections can also be added with the pop-up submenu, shown in Figure 8.4, using the Insert Section Below menu choice.

Multiple sections of the same type can help add to the flexibility in displaying information. For instance, perhaps you want to print one set of heading information on the front side of a report page, like Phone Listing, and a different heading on the back side of the page, e.g., Phone Listing - Continued.

Delete Deleting an unwanted section is easy! Select it from the list, and click the Delete button. There is a caveat, though. You can delete only sections that you have added. In other words, the five basic sections that Crystal placed cannot be deleted.

Merge If you created two sections of the same type, for instance, two Details sections, you can use the Merge button to consolidate the two sections into one. This button is active only for multiple sections of the same type. For instance, the Group Header #1a and Group Header #1b shown in Figure 8.8 could be merged together; the result would be a single line once again labeled Group Header #1. The contents of the two sections are preserved and merged.

Up Arrow This button repositions a section by moving the selected section up one section at a time through the list of identical section types. You cannot change the order of the five original sections placed in a report by Crystal.

Tip 

You can also reposition sections of the same type directly in Design mode using a drag-and-drop technique. Single-click the gray area containing the section name, hold the mouse down, and watch as the mouse pointer changes to a hand, and then drag the hand to an alternate section position to move it.

Down Arrow This button repositions a section by moving the selected section down one section at a time through the list of identical section types. As with the up arrow button, the order of the five original sections placed in a report by Crystal is static and cannot be changed.

With one of the sections selected in the list on the left side of the Section Expert, the options on the right can be used to customize the look and behavior of the selected section (refer back to Figure 8.7 for details). Table 8.1 shows the options available and to which sections they apply.

Table 8.1: Options Available by Section

Option

RH

PH

GH

D

GF

PF

RF

Free-Form Placement

X

X

X

X

X

X

X

Hide (Drill-Down OK)

X

 

X

X

X

 

X

Suppress (No Drill-Down)

X

X

X

X

X

X

X

Print At Bottom Of Page

X

 

X

X

X

 

X

New Page Before

  

X

X

X

 

X

New Page After

X

 

X

X

X

  

Reset Page Number After

X

X

X

X

X

X

X

Keep Together

X

 

X

X

X

 

X

Suppress Blank Section

X

X

X

X

X

X

X

Underlay Following Sections

X

X

X

X

X

X

X

Format With Multiple Columns

   

X

   

Reserve Minimum Page Footer

     

X

 

Read-only

X

X

X

X

X

X

X

Relative Positions

X

X

X

X

X

X

X

Section Options

Along the right side of the Section Editor are check box options that you can enable or disable. Any combination of options can be used, and in addition, formulas can be associated with the option to conditionally enable or disable it.

Free-Form Placement With this option enabled, fields and labels placed in the section reference absolute x- and y-coordinates and placement for printing purposes. This means that what you see on the screen will very closely match what prints. If the option is disabled, then the printing position of fields and labels is governed by the individual printer driver used at the time of printing. The printing of graphics, boxes, and lines drawn in a section always abides by free-form placement and uses x- and y-coordinates from the top left to the bottom right of a page. As you might guess, this can cause some undesirable results when you enclose text labels or field values inside graphics elements such as boxes. In this case, it is recommended that free-form placement be enabled. It is also desirable that all sections within a report use the same setting for free-form placement for consistency.

Hide (Drill-Down OK) The option to hide with drill-down hides a section until a user double-clicks to drill-down and reveal detail data. The Hide (Drill-Down OK) option in the Section Expert is a duplication of and is connected to the identical setting discussed above in the pop-up submenu for sections. When you choose that menu option, the check box here is enabled. Likewise, disabling it in the section submenu or in the Section Expert disables it in both places.

Suppress (No Drill-Down) The option to suppress a section completely hides it at runtime. Like the Hide (Drill-Down OK) option, the Suppress option in the Section Expert is a duplicate of and is connected to the menu option with the same name in the pop-up submenu for sections. When you choose that menu option, the check box here is enabled, and disabling it in the section submenu or in the Section Expert disables it in both places.

Print At Bottom Of Page For grouped information, using this option prints the summary value at the bottom of a page even if the information would normally have printed only halfway down the page. This option is useful for pages of documents where a summary value needs to be the last piece of information displayed, for instance, with invoice totals. When used with the Details section, this option prints/displays the detail records at the bottom of the page. This option is useful if you want data to appear below a chart or graph and consistently be anchored to the same ending place on a page.

New Page Before Use this option to place a page break before printing and displaying the section. This starts each new grouping of information on its own page when used with a Group Header section. When used with the Details section, each individual record (row) retrieved from the data source prints on a new page.

New Page After Use this option to place a page break after printing and displaying a section. This also starts each new grouping of information on its own page when used with a Group Header section. When used with the Details section, each individual record (row) retrieved from the data source prints on a new page.

Reset Page Number After When you’re printing batches of reports, for instance invoices, this option allows you to restart the numbering with each new group. Consider that the group may be based on a customer number; for each new customer number, the page counter is reset to 1. Even if there are 10,000 invoices to print, each one is guaranteed to be page numbered based on the group rather than showing “Page 741” at the bottom of a customer’s one-page invoice.

Tip 

Using the Reset Page Number After and Print At Bottom Of Page section options together gives the best results for printing groups of information that need to be considered as stand-alone units.

Keep Together An 8 1/2" by 11" piece of paper consists of about 66 lines, with around 55 of those lines dedicated to the Details section. In general, a page break will occur at its fixed place regardless of your data; the break is based on the line count. Use the Keep Together option to force Crystal Reports to keep the entire contents of a section on the same page. For instance, the Report Footer section ordinarily begins printing directly after the last record in the Details section. If you have a large amount of information displayed in the Report Footer section and you mark the Keep Together option, Crystal will insert a page break before printing the Report Footer so that the entire section appears on one page. The Page Header and Page Footer options always print at the top and bottom of a report, which means that they “Keep Together” by default.

Warning 

The Keep Together option for sections is not intended to keep groups of detail data rows together; for that purpose, use the Keep Group Together option associated directly with a group.

Suppress Blank Section If a formatted section ends up having no data in it at runtime based on filter criteria, use this option to prevent the entire section from displaying. Some sections take up a default and reserved amount of space regardless of whether they are suppressed, like the Page Footer, but using this option will minimize the amount of space devoted to blank sections.

Underlay Following Sections A section underlay is the layering of one section under another. The underlay technique can be used to place information under other information, for instance, place an image under text so that the image appears as a background. In our example scenario, we want to use the company logo as a background for every page in a report. To do this, you begin with the Page Header section and create a second Page Header. On the second Page Header, enable the Underlay Following Sections option in the Section Expert, and then place the graphic in the section in Design mode. With this option activated, the logo will appear to be under all sections up to the Page Footer section, which acts as the Page Header’s boundary. You should suppress the Page Footer (absolutely, not conditionally) since the Page Header can’t underlay the Page Footer. This technique is also known as using a watermark and can be used to place words like “Internal Use Only” and “Confidential” behind the contents of a report.

Format With Multiple Columns A simple list of names with phone numbers may take up many pages if Crystal prints only one record per line in a report. It would be handy to print this data as two columns to more effectively use the screen and paper real estate. Since this is an option that affects the rows of data being retrieved from a data source, it is available only for the Details section. When the option is enabled, an additional tab appears in the Section Expert to specify the size of the columns and the amount of space to leave between columns. Figure 8.10 shows the Layout tab with spacing information.


Figure 8.10. Formatting multiple columns

The Printing Direction option in Figure 8.10 determines whether the data in the Details section is reflowed from top to bottom and then to the next column or from left to right from the first column to the second column and then back to the first column. The Format Groups With Multiple Column option determines whether group headers and footers should be associated with the reflowed data in the Details section. With this option enabled, the data reflows and the groups stay intact and reflow as well. Figure 8.11 shows a phone listing report formatted with two columns based on the Layout information.

click to expand
Figure 8.11. Data displayed in multiple columns

Note 

The Format With Multiple Column option reflows the data in the Details section; it does not do anything to the column headers. To repeat column headers above the multiple columns, you need to manually copy and paste the headings from the original columns into an aesthetically pleasing position above the additional columns.

Reserve Minimum Page Footer Crystal Reports reserves space at the bottom of each page for the information to appear on a footer. This space is reserved whether or not there is information in the footer, whether multiple footers are used, or whether the footer is suppressed, conditionally or absolutely. Enabling the Reserve Minimum Page Footer option can minimize the amount of space set aside for a footer by using the height of the single largest footer. If this option is not enabled, Crystal adds together the combined sizes of all Page Footers and reserves that amount of space at the bottom of each page regardless of whether the footers have been suppressed or not.

Read-only If a section’s Read-only option is enabled, all other section options are disabled. Report elements in the section cannot be moved, resized, or formatted in any way. You can think of this option as a way to prevent yourself from accidentally changing things once you have the report formatted exactly as you like it.

Relative Positions The repositioning of elements in a section is generally done by dragging and dropping elements. With the Relative Positions option enabled, report elements are repositioned using the Object Size And Position dialog shown in Figure 8.12. This dialog positions the report object relative to the top-left corner of the report. The X value is used to change the position of the object horizontally from the left margin. The Y value is used to change the position of the object vertically from the top margin.


Figure 8.12. Object Size And Position

Conditionally Applying Options

In the Section Expert, the formula formatting button appears to the right of many of the section options. This means that you can use a formula to determine whether the option is applied to the section. Table 8.2 describes the three states that a button may be in. The result of the formula coded to control a section must have a value of True in order for the section to be affected. As with other formulas in Crystal Reports, you can write your code in either Crystal Syntax or Basic Syntax; see Chapter 4, “Adding Business Logic with the Formula Workshop,” for more information on formula syntax.

Table 8.2: Section Formula Icons

Icon Image

Icon Description

Formula formatting allowed; none currently in effect

Formula formatting allowed and currently in use

Formula formatting not allowed

Tip 

If the section option is selected outright with a check mark and a formula is coded to conditionally control the option as well, the formula overrides the check mark.

Conditional Formulas for Page Headers

You can also use formulas to place different headings on odd and even pages. Again you’ll make use of two similar sections, this time Page Header sections. In one of the Page Header sections, a formula is used to suppress the section if the page number is an odd number; on the other Page Header section, a formula is used to suppress the section if the page number is even. The formula in the Suppress option section on one of the Page Header sections would be

Remainder(PageNumber,2) <> 0 

While the other Page Header Suppress option section would use

Remainder(PageNumber,2) = 0 

These two formulas may appear to be incomplete at first glance since they are not wrapped in an if-then-else clause. Formulas written in the Formula Workshop need only to return a True or False value when used to conditionally control sections. Here, the built-in function, Remainder, is used to divide the current page number (accessed through the special variable PageNumber) by 2 and return the remainder from the division. For instance, if there are seven pages, Remainder(7,2) returns 1 because 2 divides into 7 three times with a remainder value of 1. The final test is whether 1 = 0; this returns False with the number 7 as it would with all odd-numbered pages.

Conditional Formulas for Group Headers

You can use formulas to add great flexibility to the sections and their behavior in Crystal. For instance, imagine that you’re printing a large report that contains groups in Duplex mode on the printer. You’d like each new group to start on a new page, but you also want that new page to always be the front side of a piece of paper. In Duplex mode, the page numbers in this situation would have odd page numbers on the front side of a paper and even page numbers on the back side of a paper. To force your group data to always start printing on the front side, you can combine the following section options that test odd and even numbers:

  • Group Footer section: Enable the New Page After section option.

  • Group Header Section: Insert a second group header (A and B).

  • Group Header A Section: In the New Page After section option, code the formula Not onFirstRecord

  • Group Header A Section: In the Suppress section option, code the formula Remainder(PageNumber,2) <> 0

The combination of these settings suppresses a blank page on the first page of the report, forces a new page for every group, and places the new group on only the odd-numbered pages through the use of the Suppress option.

Conditional Formulas for Detail Sections

The Suppress option for sections is very powerful, especially when you use multiple Details sections. Again using the Suppress option, you can conditionally hide or display a section based on the value in a field. For instance, with our Resorts table, we can selectively display a section if the value of the FiveStarRating field is Yes. To do this, in the Details section, code the following formula in the Suppress option:

isnull({Resorts.FiveStarRating}) or {Resorts.FiveStarRating} = "No"

If either condition is True, the section will not display. This means that if there is no value for the FiveStarRating field or if its value is No, the section is suppressed, which prevents that line of detail data from displaying in the report.

Multiple detail sections are used to conditionally control the appearance of the rows of data retrieved from a data source. In addition to suppressing the section as the formula above does, you can conditionally add blank lines based on field values, conditionally add boxes and graphics based on comparing values, and add color shading based on the record numbers.

Getting complex section formatting to work is a matter of thinking through in Crystal section terminology what you want to have happen, then testing and combining individual options to get the results you desire. The list of built-in functions in the Print State area of the Formula Workshop will be of great use to you in conditionally formatting sections.

Adding Color to a Section

The Color tab in the Section Expert lets you set a background color for a section. This can be done absolutely or conditionally using a formula. In Figure 8.13, you can see that you can either set the color absolutely by enabling the check box and selecting a color or set the color conditionally by writing a formula and choosing a color in the formula.


Figure 8.13. Setting a section background color

The background color is in effect for the entire section, and the objects (fields, labels, images, etc.) appear on top of the background color. You can control the color of each section independently of the other sections, so the Report Header can be one color while the Report Footer is an entirely different color.

A typical formula used to set a background color for a section is one to alternate the line shading in the Details section for easier reading of rows and rows of data. If you want every other row to be white and the alternate row to be another color, the following formula will work (where RecordNumber is the number of rows retrieved from the data source):

If Remainder(RecordNumber,2) = 0 Then    Aqua Else    White 

White is actually the default color, so you don’t have to specify it, but it makes your code much more readable if you completely express your intentions in a formula. In this formula, you could eliminate the Else clause entirely or write it as Else NoColor. If you want blocks of every three rows to be shaded a different color, a formula like this will do the trick:

WhilePrintingRecords;// Controls evaluation point numberVar x;         // Create a record counter x:= x + 1;           // Initialize counter value  If x = 6 Then        x:= 0; // Reset to zero at 6 records If x < 3 Then        // Test counter's value    Aqua              // first 3 records are aqua Else    White;            // second 3 records are white

The keywords Aqua, White, and NoColor are placeholder names that represent RGB (Red, Green, Blue) values. Figure 8.14 shows the Color dialog.

click to expand
Figure 8.14. Color spectrum

The entire RGB (Red, Green, Blue) color spectrum of the computer world is available to you. This is handy if you need to match a specific color on your company’s website or marketing material to keep your company information styled consistently. You can set a color directly using the RGB values with Crystal syntax using the following type of statement:

If CurrentFieldValue < 2741 Then    Color(151, 157, 234)     // Lavender Else    Color(255, 255, 255)     // White

In Basic syntax, you can use the RGB function call instead of the Color function. They do exactly the same thing; the RGB function name is standard in Microsoft Visual Basic and other languages.

Tip 

You can use Microsoft Paint to determine the exact RGB value of a color in a computerized image. Display the image on your computer screen, copy it to the Clipboard using Ctrl+C, paste it into Microsoft Paint using Ctrl+V, and then use the eye dropper tool to select a color from the image. The color is now stored in the primary color box and you can look up its RGB value. To do this, choose Colors > Edit Colors in Paint to open the color wheel, click the Define Custom Colors button, and the RGB value of the color you selected displays at the bottom-right corner of the Edit Colors window.

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net