2

I have set up a main report that has 2 subreports coming into it.
The main report consists of one table : ROOM & two parameters: STARTDATE and ENDDATE. The date range is only in the main report so it can be displayed in the title area. More importantly, it links to the 2 subreports.

Right now, the main report is grouped by Facility and then by Room name. Everything is working great until I try to run it for more than one day. What I want is for the main report to also be grouped by the date, but I don’t know if that is possible as the ROOM table does not contain a date field to link the parameters to so that I could use it in the groupings.

Is it possible to create a Date variable within the subreport that could then be passed back to the main report to be used for grouping? I apologize if this is a dumb question, but I do not work with variables often and shared variables even less than any other.

Ryan
  • 7,212
  • 1
  • 17
  • 30
Shannon
  • 23
  • 1
  • 3
  • 1
    How are you tying the ROOM table to the subreport data? Is there a ROOM_ID or something you're selecting for in the subreports? – Ryan Oct 25 '12 at 16:11
  • The subreports are linked by the parameter dates and the room ID. – Shannon Oct 25 '12 at 17:21

2 Answers2

1

Short answer: No. You can never group a main report with variables from a subreport. Crystal determines a report's groups early in the evaluation process, before it ever looks at any subreports.

In general, you might want to ask yourself how to avoid the use of subreports in the first place. In my mind the use of a subreport is a last ditch effort when there is simply no other way to accomplish what you want in a single report. In your case, if your main report is only made up of a single table (ROOM), then you would simply need to move the tables from your subreport to the main report, then join them to ROOM. Doing it this way would leave you free to easily group on whatever fields you wanted.

Ryan
  • 7,212
  • 1
  • 17
  • 30
  • This is how I tried to do it initially, but I want to be able to show all the rooms - even if there are no appts in the room for that date. My original plan was to do a LOJ from ROOM to PCEDATA but because the information was determined by the date field in PCEDATA, Crystal treated it like an inner join. I didnt think the grouping would work in that way, but I would rather ask and know for sure then just assume it won't... Thanks for your help! – Shannon Oct 25 '12 at 17:19
  • Ah, I see. What might work in that situation is if you left outer join ROOM to PCEDATA and then make your record selection formula `isnull({PCEDATA.DATE}) or {PCEDATA.DATE} in {@STARTDATE} to {@ENDDATE]` – Ryan Oct 25 '12 at 17:25
  • If I am remembering it correctly, that was the second thing I tried but when I did that it started pulling in thousands of records. That was when I went to the subreport because I knew that would work. I can live with it the way it is... it will already be giving them more information than I thought I was going to be able to get them... Sometimes getting 99% of what you want is better than wasting days or weeks continuing to try for 100%. Thanks again for your insight :) – Shannon Oct 25 '12 at 17:32
0

You technically can get those values from the sub-report to the main report.

This blurb describes 'Shared' scope variables.

Shared Variables (Crystal Syntax)

Shared variables use the same memory block to store the value of a variable throughout the main report and all of its subreports. Thus shared variables are even more general than global variables. To use a shared variable, declare it in a formula in the main report as in the following example:

Shared NumberVar x := 1000;

and declare it in a formula in the subreport as in the following example:

Shared NumberVar x;

In order to use shared variables, the variable must be declared and assigned a value before it can be passed between the main report and the subreport.

Shared variables are great for aggregates (sum, etc.) that span the main report and one or more sub-reports.

more info can be found here: http://publib.boulder.ibm.com/infocenter/radhelp/v6r0m1/index.jsp?noscript=1 by searching for 'variable scope'

Community
  • 1
  • 1
Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73