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

Subreports and shared variables 1

Status
Not open for further replies.

neronikita

Technical User
Feb 20, 2002
159
US
Good morning!

I have a report with two subreports in it.

The first subreport is the parts used cost report and is in group footer #2a.

The second subreport is the time worked by job report and is in group footer #2b.

They are linked to the main report by JOB ID. I'd like to be able to have a total by JOB, then a total by TRUCK, then a total by MONTH.

Here is additional information that may be helpful to explain the details:
Main report
Group 2 is grouped by trackingid(job #) and also shows the date and mileage.
Fields in details:
Workitemcompleted,CompletedBy, ComplaintSymtoms, Comments.

Subreport 1 fields (linked by trackingid)in details
Trackingid, partno, partsused (number), description, cost (per part), total parts cost (partsused x cost).
Group footer has sum of parts used, sum of total cost

Subreport 2 fields (linked by trackingid) in details
tracking id, calculation of time worked, mechanic, total cost, notes (there are a few suppressed fields that are used for calculations of the time worked totals).
In report footer a it sums the total cost of the time for all mechanics who worked that job.

Both subreports - I used insert-summary to put the totals in for total cost of parts and mechanic time, so it's not a field that I can use to put in a running total, right?

Let me know if I've confused you enough or if you need more information. I've never done shared variables, and need to know how to do that for this.

Thanks!

Di
 
Shared variables are defined in the subreport and accessed by the main report. This is an example:
Code:
Shared StringVar 
NameFound := {report.name}
Any field can be used: not just database values but also totals. And any type: number and currency and data as well as 'string'.

To access it in the main report, create another formula field with
Code:
whileprintingrecords;
Shared StringVar NameFound;
NameFound
Note that the shared variable is only available in the section after the section which contains the subreport. Proceed on that basis, see if you can get it to work. Crystal reports are best developed that way, rather than trying to work it out in advance.

PS. It helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods sometimes change between versions, and higher versions have extra options. In this case, it probably makes no difference.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
Thank you so much. I've been playing around with shared variables, but couldn't get them to work... I didn't realize they had to be in the subreport and pulled after the subreport. I really appreciate your response... I'm going to go try it now.

Sorry, I usually do give my version - it's 2008.

Thanks again,

Di
 
I must be doing something wrong... I'm getting zeros. I tried it in several spots, and it does the same thing.

This is my subreport formula:

Shared numbervar TotalPartsCostShared;
TotalPartsCostShared := Sum ({@TotalPartsCost}, {DailyVehicleTracking.DailyVehicleTrackingID})

This is what is in my main:
whileprintingrecords;
shared currencyvar totalpartsshared;
totalpartsshared

Do you see anything wrong?

Thanks,

Di
 
You have to reference the same variable name in the main report, and you are showing two different names.

-LB
 
Sorry, in the subreport it is actually

Shared currencyvar TotalPartsShared;
TotalPartsShared := Sum ({@TotalPartsCost}, {DailyVehicleTracking.DailyVehicleTrackingID})

Not sure how I got that other one copied in... I keep trying different things, and still get zeros.

Do you have to name the formula the same thing too? Does it have to be placed in the subreport and suppressed in order to use it in the main report?

Thanks,
Di
 
Nevermind, it's working now so I did something right.... Thanks for all your help!

Di
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top