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

Trouble using a shared variable in main report

Status
Not open for further replies.

dh42891

Technical User
Oct 7, 2003
107
US
Hello,

I'm using Crystal Reports 8.5 and trying to produce a report that shows the number of three ticket types a customer has used (i.e. Child Ticket). For whatever reason, I haven't been able to pull that info directly from the database- but I did find a list of how many tickets and what the price of that ticket was. So, I'm using a running total that counts the number certain ticket prices show up. Then I define a shared variable equal to that running total. Ex.:

WhilePrintingRecords;
Shared NumberVar ChildCount;
ChildCount := {#ch_from_amount}

But when I try to use that variable in the main report, I always either get a zero or nothing returned. The formula I'm using right now is:

WhilePrintingRecords;
Shared NumberVar ChildCount;
ChildCount

This, however, only returns 0.00, which is not the correct value. I know that the variable is defined correctly because I can use it in the subreport to do anything I want. I placed the subreport in the report header of the main report, but this doesn't seem to be working. I've tried to move the subreport to the page header, which would leave it still above my other formulas that reference the shared variables, but it tells me the page isn't large enough.

I'm a novice at this so I'm out of ideas and desperate for some help. Any ideas? Thanks,

dylan
 
If you are wanting the Shared variable to return the proper count for each customer, you will want to put the subreport in a Customer Grouping section in your main report.

You have stated that you have put the subreport in either the Report Header or Page Header of the main report and the most likely reason you are seeing zero in your Shared variable when you re-declare it in the main report is because the subreport is returning the value for the shared variable for the last customer it encounters regardless of which customer record you are on in the main report.

So try inserting a customer grouping in the main report and putting your subreport (make sure you are linking the main report and subreport on the customer) that generates your shared variable in the main report customer grouping and you will probably want to put your formula in the main report for showing the shared variable value in a customer grouping section that occurs after your subreport (e.g. use multiple sections or place the subreport in the customer group header and the formula for re-declaring in the customer group footer).

hope this helps or at least points you in the right direction.
 
Values returned by shared variables are only available in the next section of the report.

Madawc Williams (East Anglia)
 
Right-click and choose [Insert Section Below]. This will give you another section of the same type, if that's what you want.

More generally, running totals are often more useful than variables.

Madawc Williams (East Anglia)
 
Well, the problem with just using a running total is that when I try to put in a running total field, Crystal wants to show every record. Meaning, I have a record for every transaction (every ticket redeemed) but I don't want to show that detail, I just want a total of each ticket type and some general payment info. When I tell Crystal I want a running total split by group (which is each client) it produces records showing the client name, phone number, number of tickets, payemts, etc. for every transaction. That makes my report a few thousand pages long. I don't know how clear that was...

I'm trying the other stuff but seem to be having the same problem mrudolph suggested- that my shared variable only displays the value of the last record it evaluates. I've got the subreport in a group header, and still get zero. I tried making a Details A and Details B section, with the subreport in Details A. That, however, still displays the last value, though its not zero, and displays the subreport, which I don't want to see. If I hide or suppress Details A, my shared variable goes back to zero. All kind of frustrating, thanks a lot for the help but I'm still looking for some ideas,

dylan
 
So I got some of the right values to show up. For whatever reason, Crystal now lets me put the subreport in the details section, which is the same section I'm trying to call up the shared variable. But a handful of records aren't correct. Unless someone has some magic up their sleeve, I give up on this approach. I hate the people who set this database up. Thanks for the suggestions,

dylan
 
If you have your subreport (which generates the Shared variable) in the details section, you will want to create a Details b and put your formula that calls the shared variable into Details b because it has to be in a section that occurs AFTER the subreport.

Also double check the linking between the main report and subreport by right clicking on the subreport and choosing "change subreport links..."

In order for the customer records in the main report to match up with and select records for that customer in the subreport, you will want to link on something that uniquely identifies the customer (usually a database Customer ID field that exists in both reports). So not only the placement of the subreport and main report formulas that call the shared variable, but also the proper linking of the main report to subreport are important to ensure that the correct subreport shared variable value is passed back to the main report.

Hope this helps. :)
 
I'm not sure how to link the two reports properly. I see how to get to it, just not sure how mine should be set up exactly. I tried a few different ways but either had the same problem with a record for every transaction, giving me a thousand paged report, or some of the numbers still didn't add up. I think the incorrect values I'm getting must be related to how I'm counting the different kinds of tickets. I've emailed the people who set up the database to see if they can show me a more direct way to find the information I'm trying to calculate. I appreciate the help a lot and am sure I'll be back with some more questions,

dylan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top