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!

Counting Problem 1

Status
Not open for further replies.

ChiTownDiva

Technical User
Jan 24, 2001
273
US
I've got a problem with counting records in the report footer.

I need to count the number of records for people who are "active" and people who are "on leave".

I wrote two separate formulas to evaluate this--the first (@ActiveEmployee)is:

WhileReadingRecords;
numbervar Counter;

If {Query.PERSON_STATUS} = 'A' then
(Counter := Counter + 1)
else Counter;



The second is for everyone who's on leave (@OnLeaveEmployees):

WhileReadingRecords;
numbervar Counter;

If {Query.PERSON_STATUS} = 'L' then
(Counter := Counter + 1)
else Counter;


But I want to evaluate the people on leave AFTER evaluating the people who are active:

EvaluateAfter({@OnLeaveEmployees})

I come up with most bizarre numbers I've ever seen in my life!! If I have 2465 records, I've come up with 2113 active and 11 people on leave--sometimes if I click from design and back to preview I come up with a totally different set of numbers without even refreshing the data or report--it's wild!

Does anyone have any ideas what the heck is going on?

I've tried all types of combinations to make the numbers come out right (WhilePrintingRecords--yes, I tried that too!) and I'm baffled.

Help![sadeyes]
 
It's not clear wheere you placed the EvaluateAfter() call.

In any case, consider using a different variable for each count.

I would actually use the simpler approach of a Running Total (with a proper evaluate condition) instead of the variable approach.

hth,
- Ido CUT (Crystal UTilities): e-mailing, exporting, electronic bursting & distribution of Crystal Reports:
 
I don't find using WhileReadingRecords while trying to manipulate a count very reliable at all.

I would always use WhilePrintingRecords in conjunction with this. Why are you trying to stagger the processing time the way you are?

Most importantly, however, as IdoMillet said, definitely assign a different variable name to each of your counts. As they are, both those counts are going to get mixed up and just return gobbledegook data.

Naith
 
Hi Naith...

I really was just trying different things to try to get this to work.

I dropped the EvaluateAfter() function and renamed the variables to Jeff and Barbara so Crystal shouldn't get confused. I also used "WhilePrintingRecords" instead of "WhileReadingRecords" and I'm still not getting the correct count.

Help!
 
Jeff and Barbara. Beautiful.

Have you moved the formulas out of the Report Footer? Because remember, that section only gets processed once - hence why it looks like you're only getting the last value evaluated. If you can't move the formula, because you can't move the subreport out of the report footer, then do the count in the subreport, and pass the total to the main report RFb.

Naith
 
I need them at the end of the report, so I don't know where else to put them...

I don't have a subreport. The report is running from an SQL query.

ChiTownDiva
 
Sorry, I don't know why the heck I thought you had a subreport going on.

But if you don't, fixing this is still all good.

I realise you want the 'L' and 'A' totals displayed at the end of the report, but you have to actually processing the counting in the details or group.

Put {@Active...} and {@Leave...} in the details section, and then in the Report Footer place two formulas which call the count values:

//{@Active Call}
WhilePrintingRecords;
NumberVar Jeff;

//{@Leave Call}
WhilePrintingRecords;
NumberVar Barbara;

Naith
 
Counting problem solved...

Thanks, Naith!!! [2thumbsup]

ChiTownDiva [ponytails]

PS: Know anything about stored procedures. I need to write one to use in Crystal...in particular this one!
 
I know what I'm doing with Oracle or Sybase SPs, but quite a fair few people here are SP buffs - lyanch springs to mind, if I may point the finger.

I don't know what database you're using, but it might help you to go to:


and search for SCR_Oracle_Stored_Procedures.pdf

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top