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

Subreport or Array

Status
Not open for further replies.

psamedy

Technical User
Apr 22, 2002
60
US
Hello All,

I'm running Crystal v10 against a Ms SQL 2000 db.
I have a one to many relationship between two tables (Person, Company).A person can belong to many companies.
I need to create a report that displays something like the following. It would be grouped by person.id

person.id
person.name
person.address
company.name {printing all companies per personID}

Must I create a subreport for this or can I create an array that accumulates the names before they are displayed? If an array is possible what would the code look like. Thanks Pat


 
I'd do it with an array. Group on {Person.ID}, and create 3 formulas:
[tt]
//@Init
//Put this in the Group Header
//This formula isn't necessary, but it's a good practice
WhilePrintingRecords;
StringVar Array CompanyNames;
"";

//@AddToArray
//Put this in the Details section
WhilePrintingRecords;
StringVar Array CompanyNames;
if onfirstrecord or {Person.ID} <> previous({Person.ID}) then
ReDim CompanyNames[1]
else
ReDim Preserve CompanyNames[UBound(CompanyNames) + 1];

CompanyNames[UBound(CompanyNames)] := totext({Company.Name});
"";

//@Display
//Put this in your Group Footer
//The end result is a comma separated list of companies for this person
WhilePrintingRecords;
StringVar Array CompanyNames;
Join(CompanyNames, ", ");
[/tt]
Suppress the Group Header and the Details section, and lay out the Group Footer like this:

{person.id}
{person.name}
{person.address}
{@Display}

Make sure to set the @Display formula to 'Can Grow', and make the field as wide as you like.

-dave

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top