Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Group question

edited June 2006 in General
I have a report that has a group, which based on a checkbox on the main
form I want to use or not.

So if the checkbox is NOT checked, my query looks like this:

select NAME, CODE, sum(COST) from table
group by CODE
order by CODE

or if they check the checkbox, I build the query with the group like so:

select NAME, CODE, sum(COST) from table
group by NAME, CODE
order by NAME, CODE

When I designed my report, I created a group based (with a new page
reset) on the NAME field and I hide the group header fields in a
OnBeforePrint of the group header band if the checkbox is not checked.

Works good, except for one thing. If the user runs the report without
the group (checkbox unchecked) first, it looks great. Then close the
report preview, check the checkbox (so now it should be grouped), the
report is somewhat grouped by not really. Instead of showing the first
page being just the first instance of NAME and all it's codes + sum'ed
costs, it is all the NAMES codes + codes summed up.

Page 1
Code Total
A 10
B 20
C 15
A 99
B 13
C 18

instead of

Page 1

Code Total
A 10
B 20
C 15

Page 2

A 99
B 13
C 18



Either way the user starts, with the checkbox checked or unchecked the
report looks great. So if the first time they run the report with the
checkbox checked, it breaks the pages just fine and my group header band
shows up.

It's just messed up if they run the report once ungrouped, and then
immediately run again with it grouped. I get the strange half-grouping.

I'm closing all datasets that the pipeline the reports uses each time
the reports is run.
I requery the database each time the report is run with the appropriate
query.
Looking at the groupbeforeprint event, the code to hide/show the header
band shows that the checkbox is correct (band.visible := checkbox.checked).


I'm using Delphi 6, Report Builder 7.04.

Any ideas on what I'm doing wrong or how to avoid the problem?
Daniel

Comments

  • edited June 2006
    Since I couldn't get it to work and I have had trouble with reusing
    components without re-creating them before, I thought I would try
    re-creating this chain of controls each time.

    TSQLDataSet->TDataSetProvider->TClientDataSet->TDataSource->TppDBPipeline

    and now it works just fine.



This discussion has been closed.