2012-10-26

Crystal Reports - Create index page - Part 2

In Crystal Reports - Create index page - Part 1, the normal situation is 1 chapter tile/cross-tab/chart along with 1 chapter/table/figure index sub-report, and I have a sub-report which its number of total page up to 26. In this sub-report, I create a cross-tab and place it in Group Footer, unfortunately Crystal Reports doesn't support 3 tier sub-report, so I can't use index sub-report.



I drag a new created formula @Title under cross-tab's position, and there is a shared variable page_number (page_number := PageNumber) in the main report. In the beginning, I thought just need to retrieve the variable's value into @Title, so original structure in @Title as follows:
WhilePrintingRecords;

Shared StringVar title_name;
Shared StringVar title_number;
Shared StringVar title_type;
Shared StringVar title_page;
Shared StringVar title_level;
Shared NumberVar figure_number;
Shared NumberVar page_number;
NumberVar page_number_sub;

Shared StringVar financial_flag;

figure_number := figure_number + 1;
page_number_sub := page_number;

title_number := title_number & 'Figure ' & TOTEXT(figure_number) & '.,';
title_name := title_name & 'Cross-Tab Name ' & {@@Machine_Code} & ' - ' & {usp;1.period} & financial_flag & ' (Part ' & TOTEXT({@@Page_Break}) & ' of ' & TOTEXT({@@Horizontal_Page_Number_Total}) & '),';
title_type := title_type & 'Figure,';
title_page := title_page & TOTEXT(page_number_sub) & ',';
title_level := title_level & '1,';

'Figure ' & TOTEXT(figure_number) & '.   ' & 'Cross-Tab Name ' & {@@Machine_Code} & ' - ' & {usp;1.period} & financial_flag & ' (Part ' & TOTEXT({@@Page_Break}) & ' of ' & TOTEXT({@@Horizontal_Page_Number_Total}) & ')';
Then, I encountered two problems:
1. Sub-report doesn't capture correct page number, except the first page in sub-report, all the rest of pages display the same page number as the first page, for example, I place sub-report in the page 50 of main report, then every page's page number in sub-report displays 50.
2. If I execute sub-report in stand-alone status, only needs 1 minute to finish executing, if I execute it inside the main report, it takes really long time to finish running (almost 26 minutes = 1 minute * 26 pages), even I click Show Previous/Next Page or jump to specific page, it will automatically refresh for that page (another 1 minute).

After sacrificed couple of weekends in waiting and testing, finally find variable page_number is the major problem. The following is my fixed way:
1. Drag a new created formula @Page_Number_Prefix to the section before sub-report, suppress it and input script:
WhilePrintingRecords;
Shared NumberVar page_number_prefix1;
page_number_prefix1 := PageNumber + 1;
2. Modify script of @Title in the sub-report:
Shared NumberVar page_number_prefix1;
NumberVar page_number_sub;

Shared StringVar financial_flag;

figure_number := figure_number + 1;
page_number_sub := page_number_prefix1 + PageNumber - 1;
As you can see, the script of @Title is a bit different from SubRerpotForTitle_Figure.rpt, because I need to display like "Part Group_Page_Number of Group_Total_Pages" in each group's title, e.g. Part 1 of 4.
Next time, I will introduce how to design dynamic column number and position of cross-tab, and sub-total page number for each group. 

No comments:

Post a Comment