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

Confused Consternation with Subreports and shared variable 1

Status
Not open for further replies.

TheBigO

Programmer
Feb 4, 2002
16
US
Thanks for listening. I'm using CR 8.5.

I have a report which is set up to print information for one department based on the parameter it is passed. The report should show the department name and department number in the page header. In the detail it should show all 10 digit account numbers and subtotal them, then show all 4 digit account numbers and subtotal them and then show a grand total. THe problem is that sometimes there are no 10 digit accounts but there are 4 digit accounts for a department. In this case, Crystal will not show the department name or any 4 digit accounts even though they exist. What am I doing wrong here?

Here is my selection formula in the MAIN report:

Length({AccountSheets.Account}) <> 4 and
{Departments.Number} = {?DepartmentNumber}and
{BudgetAccounts.AcctType} = &quot;I&quot;

Here is my selection formula in the SUB report:
Length({AccountSheets.Account}) = 4 and
{Departments.Number} = {?Pm-Departments.Number} and
{BudgetAccounts.AcctType} = &quot;I&quot;


Here are the shared variables I am using which are declared in the header of my SUB report:

Shared StringVar account := {BudgetAccounts.Account};
Shared StringVar description := {AccountSheets.Description};
&quot; &quot;

 
Depending on how the subreport is linked to the main report, I would guess that the subreport is not even running when there is no data in the main report (no 10-digit accounts).

You might try pulling the 10-digit account data in a separate subreport, then having a main report to select account type and department number and link both subreports to that.

Alternatively, if you want to work within the structure you already have, you could take the

Length({AccountSheets.Account}) <> 4

out of the Main report selection formula. Then change the format of each main report section so that you conditionally supress it. Check &quot;Suppress&quot;, then hit the &quot;X+2&quot; formula button and add something along these lines:

if Length({AccountSheets.Account}) = 4 then DefaultAttribute
 
Based on what I think you're trying to do, you're making things way too complicated. You don't need all those parameters, sub-report or shared variables.

The only parameter to the report, it seems to me, is the department number.

Create a formula that is simply the length of the account number (as I understand it, this will be 10 or 4).

Create a group, order descending, on that formula. You will now have a group for that length 10 account numbers and a group for the length 4 account numbers. Create running totals per group and place that value in the group footer.
 
balves,

Thanks. that works.

However, when there is a department which has no 10 digit account numbers, the report won't print the subtotals for the 10 digit accounts. It will only show the information for the 4 digit accounts.

How do I get it to to print out a sub-total for departments having no 10 digit account numbers?
 
Thanks lfl and balves for your help.

balves,

I used your approach and it works.

However, when there is a department which has no 10 digit account numbers, the report won't print the subtotals for the 10 digit accounts. It will only show the information for the 4 digit accounts.

How do I get it to to print out a sub-total for departments having no 10 digit account numbers?
 
That should be pretty easy.

Assuming you have a Group now in your report.

Right-click on the group header and select &quot;Insert Section Below&quot; so now you have a Group Header 1A and 1B. You can hard-code in one of these sections &quot;10 digit numbers - Count 0&quot; or however you're displaying the count. Or do the same with the Group Footer.

Use either 1A or 1B. Right-click on the section (1A or 1B) and choose &quot;Format Section.&quot; Then click on the &quot;Suppress&quot; checkbox and then on the Formula icon next to it.

When the formula editor opens, use your formula variable (e.g., frmlaLenAcctNo) like this:

(frmlaLenAcctNo = 10) or (frmlaLenAcctNo = 4)

In other words, when the length is 10 or 4 suppress this section. Otherwise, it will display whatever you've hard-coded into it about 10 digit numbers missing.
 
I have found a useful method of countering Crystal not printing a total of zero when there are no records for it to produce its totals ( in your case when there are no 10 digit Accounts).
I insert a text field of zeroes underneath the summary calculation field. I suppress this field printing when the summary total is not null. If the summary total is null, however, it prints a nice zero where you need it too be.
I use this because blanks in a report confuse users when they are expecting at least a zero.
 
2 more questions:

1 - Under &quot;Format Section&quot; do you choose &quot;Suppress(No drill-down)&quot; or &quot;Suppress Blank Section&quot;?

2 - I want it to suppress if there are 10 digit numbers
AND 4 digit numbers. I Want to show it only when there are no 10 digit numbers. THe problem is if I put the formula in there as above ({@Length}=10) or ({@Length}=4) the message will never appear because there will always be at least one 4 digit account. So I put the formula in as
({@Length}=10) and ({@Length}=4). This works fine when there are no 10 digit account numbers however if there are BOTH 10 and 4 digit account numbers it shows up anyway.

Any suggestions?


 
Another idea I had was to to suppress a section if the number of records of a certain length equals zero?
I.E. the formula:

count({@Length}=10)=0

I tried this and it gave me an error message saying
&quot;The summary/running total field could not be created&quot;
 
1. It's &quot;Suppress(No drill-down)&quot;

2. You're right. The Suppress formula doesn't work in all cases.

I've got a different idea. There's a function called GroupNumber. It counts groups in the report. To see it, just create a formula and simply put GroupNumber as the code and drop it on a group header.

So, assuming that you have your hard-coded text in Group 1A or 1B, the suppression formula would be:

(groupnumber = 1 and {@Length} = 10) or
(groupnumber = 2 and {@Length} = 4)

So if you're on groupnumber 1 and the @Length is 4, then there is no 10-digit and your hard-coded text about No 10-digit numbers would be there. Otherwise it's suppressed. Same if the second group is the 4-digit.
 
balves...you're a genius!

It worked, by golly, it worked!

Thanks for all of your help. I learned a ton today:)

TheBigO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top