Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: SubReports & Shared Variables Post Reply Post New Topic
Author Message
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Topic: SubReports & Shared Variables
     Posted: 20 Jul 2011 at 4:44am
Hello All
 
I have a main report that shows invoiced sales by customer.  I want to show the orders on the same report.  I have created a sub report and linked the 2 and it works ok.
However I now want to add the 2 figures together so need a shared variable to pass to the main report(I think!).
What I end up with is a list of customers, showing the sales and the orders.
But when it gets to a customer with no orders it shows the orders from the previous customer and repeats this for all customers below until a new customer is reached with orders and then it  displays the new total.
If the customer below has no orders it repeats the same total again.
 
Please Help!
brockloch
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 20 Jul 2011 at 5:09am
You need to be sure to set the shared variable to 0 at the start of every customer.  In the main report try doing something like this:
 
Shared NumberVar Sales;
If {table.customer_id} <> previous({table.customer_id}) then Sales := 0;
Sales
 
-Dell
IP IP Logged
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Posted: 23 Jul 2011 at 12:32pm
Thanks for your help - I got it working.  Basically the sub report for the customer held no data so it picked up the info from the previous customer.
Your advice worked - why does it pick up the previous customer?
Thanks again.
brockloch
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Jul 2011 at 1:44pm
Because if there's no data in the subreport, it doesn't know to set it to 0.  No data (null) is NOT the same thing as 0, so it gets handled differently.
 
-Dell
IP IP Logged
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Posted: 24 Jul 2011 at 11:22pm
Thanks
brockloch
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum