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!

Using a While Loop with Crystal Reports 8 1

Status
Not open for further replies.

clydejones

Programmer
Jan 11, 2001
153
US
Hi,

I am using Crystal Reports 8 and would like to loop through a table to count how many records there are containing a certain text or value. From what I read, I should be able to use a While Loop to do this, but I have not figured out how to do it. Shouldn't I be able to loop through a table to count the number of records that contain a certain text or value? I have tried using the Running Totals Field by using a formula like {tableName.fieldName}= "myDesiredValueToCount", but the count is incorrect. If anyone can lead me in the direction as to how to count records with a While Loop or correctly use the Running Total Fields, I would appreciate it. Sorry for the long explanation.

Thanks In Advance,
Clyde



 
While loops in CR do not loop through a table, they allow you to go through a single record mulltiple times.

You need a conditional total, which can be done several ways. I would use a two formula technique:

First create a formula field with the following pattern:

If "TestValue" in {field}
then 1
else 0

Now you can do a Grand Total Sum of this column (which will result in a count of records) and place the result at either the beginning or the end of the report.

If the total is incorrect you can check to see which records are getting a one and which are getting a zero. You can also use the running total technique that you described but a running total will only be complete at the end of the report, while the technique I describe can be shown at the beginning.

Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Clyde,
I would suggest that you should consider using stored procedures to create your data sets for SCR, as you will have a lot of flexibility in doing the sort of stuff you are describing. Using running totals or incrementing variables can often give the result, but it is slower to execute, code, and more prone to coding error.
But you asked how to do it with running totals, and Ken gave you the unvarnished truth...
good luck :) Malcolm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top