Monday, February 29, 2016

Crystal Reports : Linking a Subreport

Once your subreport has been embedded, it can be then linked. If the subreport has nothing to do with the main report, data-wise, then leave this part alone.

However, if the subreport has parameters, we must decide what to do with them. Because if you leave them unlinked, the end user is prompted for them alongside the parameters for the "main" report.


 

The idea is to select a parameter from the "Available Fields" list, add it to the right side and then select the subreport parameter it should be linked to. This way, the end user (in this case) is only prompted for one date range instead of two.

A few considerations;

1. The data types in the main and subreport(s) must be identical when Linking, otherwise they won't show in the drop down. This literally just happened to me a moment ago when producing this screenshot. 

2. Do yourself a favor and name your parameters consistently. In this example, the Date_Range parameter from the main is linked to the Date_Range parameter in the sub. 

3. If there is no corresponding parameter in your subreport, you can try using the "Select data in subreport based on..." checkbox. Results vary. If you're willing to embed a subreport, go the entire distance by creating matching parameters.

And as ALWAYS keep backups. 
 

Crystal Reports : Inserting a Subreport

To actually insert a subreport, this is done via Insert | Subreport.

 

A few things to consider;

1. You can choose an existing or "new" report (invoking the new report wizard). I HIGHLY recommend choosing an existing report. The reason being is that you want this report to be as finished and polished as possible before embedding it. I also recommend that you keep backups of your subreports.

2. The subreport is just another Crystal Object to be inserted onto the Layout. Therefore, take care where you put it. Subreports are almost always used at the Header or Footer level. Putting them into a Details section can greatly increase your refresh time.

3. If there are parameters to be fed within the subreport, these must be linked or the end user will need to fill them out every time. 

And this is what you end up with, an "rpt" object. Much like a Notes field, it will grow itself accordingly to it's needs upon refreshing. 


Crystal Reports : Why should you care about Subreporting?

I have a love/hate relationship with Subreports. It's true, I owe them mightily for the occasional bailout from bad situations. They are an excellent method to display data from somewhere completely unrelated in a quick-and-dirty way.

Simply, this is way to insert a Crystal Report inside another. Think about it like inserting an image file into a document. The subreport is for all intents and purposes, its own full-blown crystal report.

The two reports can be related via "links", or they can be completely separate. When a subreport is linked, you can pass things like parameters to it. So, if your "Main" report is prompting for a Date Range, you could then pass on that same selected Date Range to a subreport parameter. This is what I personally struggle with sometimes. 

However, if they are separate (not linked) it's simply a way to have two or more reports all embedded into one "main" report. I've seen this used a few times in the field, and it can be useful.

But the more experience I got with Crystal and SQL, the more I found myself using alternative methods to get and display data. Subreports are often used when you're trying to work yourself out of a corner; in a perfect world, all your data is returned as relatable (i.e. joinable) tables or views. If this isn't the case, it's almost always better to fix the underlying problem rather than clutch at subreports out of desperation.

It's because of this that subreports are rarely used. Consequently, I find myself having to learn them "all over again" from time to time.

So, here are a few things I consider when getting ready to us a subreport;

- Do I need to use a subreport to return my data? Is it otherwise accessible via a table or view?

- Once I add a subreport, it becomes a little difficult to get formatting to look just right. I might find myself spending hours fine-tuning the appearance of the layout.

- Embedded subreports can be confusing to modify after-the-fact. They appear in the "main" report as objects, and must be right-clicked and edited in a separate tab. If I open a mess of tabs in Crystal, I might lose track of where I am and start editing the wrong thing.

- Subreports will add time to the report refresh duration.

And now, without further adieu, we can move on and actually see how they work.

GoldMine : What's in a Summary Tab?

The unsung hero, the Summary Tab! It looks pretty useful, but did you know exactly where all these values are coming from?

 

Comments : This is a free form text field that is for manual use by the end user.

Prev Result : This is auto-filled with the Reference from the last completed History.

Next Step : This is auto-filled with the Reference from the next Pending Activity.

Next Action, Call Back, Appointment, and Forecast :  These show the next pending dates of their corresponding Activity Types.

Last Contact : The date of the most recently completed Phone Call or E-mail.

Last Attempt : The date of the most recently completed Unsuccessful Phone Call. (Identified using the "Success" drop down in the Complete a Phone Call history dialog)

Last Update, Creation : These are the dates of when the last Contact Record update was performed and it's creation, respectively.

Tune in... to the next live Tips and Tricks webinar to learn how to Filter on these values!