Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

showing all groups contained on a page 1

Status
Not open for further replies.

hb2

Programmer
Jul 22, 2002
20
GB
version: CR 9

I'd like to summarize the groups that appear on a page. For example if the following appear on page 1:-

Group1
Detail1
Detail2
Group2
Detail3
Detail4

and then on page 2 these appear:-

Group3
Detail5
Group4
Detail6
Group5
Detail7


I'd like the Page Header of page 1 to have a title of 'Group1/Group2' and page 2 to have 'Group3/Group4/Group5' as a title.

thanks in advance
 
You would think this would be easy, but it's not. If you are willing to use a subreport and display your groupname in the details section only, you can do this as follows.

You can place the group name in the details section and then format it to "Suppress if duplcated", so that it appears only on the first record in the group. Suppress the report header or format it to "new page after" so that all pages have the same sections. Then create a formula {@linecnt} and place it in the detail section:

whilereadingrecords;
numbervar linecnt := linecnt + 1;

Once you have noted the last number on the first page, modify {@linecnt} so that it creates intervals based on that number (e.g., 45):

whilereadingrecords;
numbervar linecnt := linecnt + 1;

if linecnt in 1 to 45 then 1 else
if linecnt in 46 to 90 then 2 else
if linecnt in 91 to 135 then 3 else
if linecnt in 136 to 180 then 4 else 5

Add intervals up to the maximum number of pages. Next insert a group on {@linecnt}. Go to the change group expert and make the new group the topmost (outer) group. Then make sure that your new group appears at the top of each page. Then suppress the detail section.

Insert a subreport that uses the fields you want displayed and which is grouped as you desire, but again, you will move the group name to the detail section and suppress all other sections except the report header_a. Copy the {@linecnt} formula from the main report and add it to the subreport, placing it in the detail section. Then link the subreport to the main report by linking the two {@linecnt} formulas.

To get the group names at the top of each page, create a formula within the subreport like the following:

(
if distinctcount({table.groupfield}) = 6 then
"Group " + totext(maximum({table.groupfield}) -5,0,"") + "/"
)+
(
if distinctcount({table.groupfield}) >= 5 then
"Group " + totext(maximum({table.groupfield}) -4,0,"") + "/"
)+
(
if distinctcount({table.groupfield}) >= 4 then
"Group " + totext(maximum({table.groupfield}) -3,0,"") + "/"
) +
(
if distinctcount({table.groupfield}) >= 3 then
"Group " + totext(maximum({table.groupfield}) -2,0,"") + "/"
)+
(
if distinctcount({table.groupfield}) >= 2 then
"Group " + totext(maximum({table.groupfield}) -1,0,"") + "/"

else
"Group " + totext(minimum({table.groupfield}),0,"") + "/"
) + "Group " +

totext(maximum({table.groupfield}),0,"")

Add clauses as necessary based on the maximum number of groups that can appear per page. Place this formula in the report header_a of the subreport.

Basically this approach limits the records in the subreport to those that can appear on one page. The subreport then can use summaries to determine maximum and minimum per page. This does assume that the groups are based on sequential numbers and that no groups are missing. If this isn't the case, you could alternatively use minimum and maximum to show the range of groups displayed. For example, if the groups are strings, e.g., hotel names, a grouping would display alphabetically, and you could show "Red Roof Inn to Ritz Hotel".

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top