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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the grouping field at runtime 1

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hi All!

I have an interesting situation. I have a report with 3 groups. Group1 is based on a field from a database table (say, county.countyId). The report prints correctly and I'm happy, but I need to create the exact same report having the first group based on a field from a different table (say, city.cityId).

It works sort of like this: I have a table containing (among others) the following fields:

1 - countyId (which points to the 'county' table)
2 - cityId (which points to the 'city' table)
3 - stateId (... state table)
4 - and so on...

Group 1 of the report I have right now is based on countyId, and records are nicely grouped by county. However, the user has the choice to print by city, by state, and by other fields whose structure is exactly the same as county.

I could simply save the new report with a different name and just change Group 1 to base it on cityId, and then do that again for stateId and the others, but then I would wind up with 5 different reports which are essentially the same, but that differ only in the way they're grouped.

Thus, the question is: Can I change the field a group is based on at runtime so that I only create 1 report and print it based on the user selection?

I'm using Crystal Reports 10.0 and I'll be instantiating the report from C#.

Thanks!

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Create a discrete string parameter {?Group} with options like "County", "State","City", etc. and then create a formula {@group}:

if {?Group} = "County" then {table.countyID} else
if {?Group} = "State" then {table.stateID} else
if {?Group} = "City" then {table.CityID} //etc.

Then insert a group on {@group}.

-LB
 
Thanks LB!

You the man! Is there anything for which you don't have an answer [thumbsup2]?

The user won't be interacting with the report itself, though. The user will see a .NET webform which will include other things besides the parameters for the report, and they'll only see the report through a ReportViewer object. Can my C# code interact with the {?Group} parameter?

Thanks!

JC


_________________________________________________
To get the best response to a question, read faq222-2244.
 
Well, there ya go--something for which I don't have an answer--but I'm sure there are other people here who can.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top