Shared Variable not displaying correct value in main report (1 Viewer)

Lissa

Registered User.
Local time
Today, 15:09
Joined
Apr 27, 2007
Messages
114
Hi everyone,
I can't seem to figure out what's going on with my Crystal Report (XI).
I built a report that displays patient cancellations. I have to calculate the number of days since their last completed appointment.
On the main report I have the list of cancelled appointments. I created a subreport grouped by patient ID # to pull the latest completed appointment. (Patient ID# and appointment type are supressed fields in the sub report). I added the subreport to the main report by just inserting the entire report in the detail section of the main report. The subreport is linked to the main report by the patient's ID # and the type of appointment. This works perfectly.... however I forgot I had to calculate the number of days between the appointments.

So... to use the latest appointment value in a formula in the main report, I created a shared variable in the subreport and display it in the main report. The Shared variable is placed in the detail section of the main report.

Shared variable code in subreport:
shared datetimevar maxApptDt;
whileprintingrecords;
If isnull({Schedule.Appt_DtTm}) then DateTime("01/01/1900 12:00:00 PM")
else
maxApptDt := maximum({Schedule.Appt_DtTm})

Shared variable code in main report:
whileprintingrecords;
shared datetimevar maxApptDt;
maxApptDt

My main report now displays different values for the latest appointment when I'm thinking they should display the same values. The shared variable seems to be one row off - like the values shifted down.
For example:
Main report display
(@maxApptDt)
Patient ID Appt Date Last Appt subreport
XXXXXX 5/27/2015 8:45AM <blank> 5/27/2015 5:00PM

YYYYYY 5/27/2015 9:00AM 5/27/2015 5:00PM <blank>

ZZZZZZ 5/27/2015 9:30AM < blank> 5/20/2015 9:30AM

AAAAAA 5/27/2015 10:00AM 5/20/2015 9:30AM 5/20/2015 10:00AM


For patient XXXXX I am expecting the shared variable @maxApptDt to return the date of 5/27/2015 5:00PM since they were fit in to see the doctor at a later time... but that time appears for patient YYYYY instead.

Any ideas on how I can fix this? :banghead:

Thanks!!


 

Lissa

Registered User.
Local time
Today, 15:09
Joined
Apr 27, 2007
Messages
114
Issue resolved...

After playing around with different options I eventually resolved this myself by inserting another Detail line and placing the shared variable in that section. I end up referencing that shared variable in a formula in the Details b line.
 

kevlray

Registered User.
Local time
Today, 13:09
Joined
Apr 5, 2010
Messages
1,046
Not sure what is happening in your case. But a couple of things to remember with sub-reports and shared variables. One, the sub-report needs to be in a section prior to where you want to use the shared variable in the main report. Second. Always set a value for the shared variable in the sub-report or it will retain an old value.
 

Users who are viewing this thread

Top Bottom