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

exclude dates in subreport 2

Status
Not open for further replies.

johnhugh

Technical User
Mar 24, 2010
702
SG
Hello,

I'm working in Crystal 10.

I've written a subreport which shows me the last date an item was shipped

Code:
shared numbervar lastdate;
lastdate:= Maximum ({ICHIST.TRANSDATE});
pwformatdate(lastdate)

In my main report I now want to exclude all items which have been shipped in the last 6 months. I couldn't work out a formula so I created a parameter field where the user enters a cut off date.

I have linked the parameter field of the main report to the lastdate field of the subreport.
So now I have the cut off date parameter field in my subreport.

How do I now exclude dates which are later then my cut off date?
I tried the code below in the record selection editor but it won't allow me to add @lastdate.
Code:
(@lastdate) < {?Pm-?SelectCutOffDate}

Any help is much appreciated.


 
It would be easier to eliminate the parameter.

calculate date 6 months back from currentdate

dateadd("m", -6, currentdate)

if you want first of the month 6 months back

date(year(dateadd("m", -6, currentdate)), month(dateadd("m", -6, currentdate)), 1)

Ian
 
I think you should change your subreport formula to:

whileprintingrecords;
shared numbervar lastdate;
shared datevar inlast6mos;
if pwformatdate(Maximum ({ICHIST.TRANSDATE})) >= dateadd("m",-6, currentdate) then
lastdate:= Maximum({ICHIST.TRANSDATE}) else
lastdate := date(0,0,0);
inlast6mos := pwformatdate(lastdate);

Then in the main report reference inlast6mos to suppress unwanted items:

whileprintingrecords;
shared datevar inlast6mos;
inlast6mos > date(0,0,0)

This assumes thate pwformatdate converts the number to a date, not a string.

-LB
 
Thank you for your replies. The formula makes it a lot easier.
I think I'm getting closer.

This part won't work though. Crystal tells me it requires a number for lastdate.
Code:
lastdate := date(0,0,0);
So I've changed it to this:
Code:
lastdate := 0;

My numbers in my main report appear to be correct now.
Last problem I seem to be facing is to display them correctly as well.

The fields I reference to from my subreport always appear 1 row after the actual row where they belong, e.g. if I want to suppress one field in my main report Crystal actually suppresses it on it's next run through. Also the first row of my main report is always empty for referenced fields from the sub report.
It's like the main report always is one step behind the sub report.

Does this make sense?
How could I avoid this behavior?





 
Subreports always execute after the main report, if you are then using the subreport variables to suppress data in the main report at printime it can only do so after the the SR has run.

YOu need to place the SR in a section above the main report data which is to be affected by data being passed from the SR.

Ian
 
Thanks Ian. I've got it working now.

In the section expert I've set the section containing the sub report to be suppressed if blank.
I've hidden the sub report as well but still I cannot get the subreport to be suppressed causing white gaps in my report.

Can sub reports be suppressed in the main report or does this only apply to fields?
 
With CR10 you can format subreport to be suppressed if empty.

Right click subreport object select format and then subreport tab, check suppress if blank.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top