Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Subreport - name defined in returned field Post Reply Post New Topic
Author Message
CaptnTony
Newbie
Newbie
Avatar

Joined: 15 Jun 2012
Location: United States
Online Status: Offline
Posts: 11
Quote CaptnTony Replybullet Topic: Subreport - name defined in returned field
     Posted: 18 Jun 2012 at 6:35am
I'm very new to CR (using 2008 until my upgrade arrives) but have a pretty good bit of experience in other reporting tools.

What I've been tasked with for this first report is to be able to run a report which has a set of tests (manufacturing QA tests) which must be performed on the products manufactured. These tests differ depending upon which customer is ordering them and which product is being manufactured. Right now, I'm just trying to make things work based on which Customer is ordering the product.

Basically I want to create a "master" report which pulls the current information about the production plan out of our ERP system (can do that just fine). Then, based on that information I need to have the master open a sub-report to find which compliance report must be printed (the report name is stored in the customer table in the ERP). So I've got a link to the production job and customer ordering the item. This is where it gets 'hairy'. Depending upon the information stored in the customer record, I'd like the default analysis template (responsible for looking up the name of the customer from the passed in job information). I have that report look up the name of the subreport (part of which is stored in the customer record). I then want the subreport in the template to link, not to a predefined report, but to a report based on a variable name found via the current report's command source. (new to the terminology too, so it may not sound correct, so I'll try to map it out a bit in case that makes more sense)

Run Packet (Uses jobID from ERP to open CoATemplate rpt)
|----> CoATemplate (finds specific CoARpt based on customer information looked up with jobID information)
   |----> CoA-??? (specific test information for the test name retrieved in the CoATemplate subreport. ie: if the CoATemplate command returned a field named CoAReport with the string value: CoA-001, I'd like to have the CoATemplate open a subreport called _PC_CoA-001.rpt in a specified path (I'd keep them all in the same path so I could append the report name string to the <path>\_PC_ string.

Is something like that possible? Can the report which contains a subreport have a command statement return the value "report" name and have it dynamically assigned to the subreport value?

The command built as the source of the CoATemplate report is something like:

SELECT 'Z:\ERPfolder\Reports\_PC_' + cust.rptName + '.rpt' AS CoARpt
FROM   job INNER JOIN cust ON job.custno = cust.ID
WHERE job.jobID = {?pJobID}

In theory, it would return the CoARpt column with a value that looks like: Z:\ERPfolder\Reports\_PC_CoA-001.rpt

I'd have to find the TRIMALL() sort of command to remove any spaces before and after the cust.rptName data of course and modify the SQL statement a bit.

I'd then like the CoATemplate to use the generic subreport defined to open up the actual report found in the location stored within the CoARpt column.

Ideas or other links that may help me find an answer are GREATLY appreciated! Thanks in advance

Todd
Just because you can doesn't mean you should.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 18 Jun 2012 at 7:39am
If I understand you correctly, you want to have a subreport dynamically open with a specific report based on what the user selected.  Is that correct?
 
If it is, it can't be done - there's no way to specify which report to open in a subreport from within Crystal.  What you will have to do is add all of your possible subreports to the main report and use the suppression formula in the Section Expert and on each subreport itself to selectively suppress/show the subreports based on the data.
 
-Dell
IP IP Logged
CaptnTony
Newbie
Newbie
Avatar

Joined: 15 Jun 2012
Location: United States
Online Status: Offline
Posts: 11
Quote CaptnTony Replybullet Posted: 18 Jun 2012 at 10:06am
Thank you for the quick reply hilfy, I appreciate the info!

I'm guessing it's the same thing, but I don't want to open up a report based on user input after the report is generated. The subreport loaded would be defined by a string I provide with a variable appended within the string (see the select statement above). This variable would be determined at the time the "template" subreport is opened and the data is defined in the Command data source. I'm guessing the issue is due to compile issues for the report and I didn't really expect it to be 'that easy' :)

I really don't like the idea of defining each and every report within it's own band and then suppressing those that aren't used (could be upward of 25-30 reports right now and growing as customer demands change).

Thanks for the help.
Just because you can doesn't mean you should.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 19 Jun 2012 at 3:19am
Unfortunately, there really is no other way of doing it.  You might be able to run the report externally from an application you write with the SDK that will set the linked .rpt file for the subreport at run time.  The challenge then will be getting the subreport links set up correctly.  I haven't actually looked at this to see whether it can be done, though.
 
-Dell
IP IP Logged
CaptnTony
Newbie
Newbie
Avatar

Joined: 15 Jun 2012
Location: United States
Online Status: Offline
Posts: 11
Quote CaptnTony Replybullet Posted: 19 Jun 2012 at 1:21pm
Yeah, I'm starting to think that it may be the only way too after a day and a half of trying to find alternatives (testing and on the web).

Thanks again for the pointers. I do appreciate the help learning Crystal.

- Todd

Just because you can doesn't mean you should.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum