Link to home
Start Free TrialLog in
Avatar of running32
running32

asked on

Crystal Reports and VS2003 - loop through dataset

I have a crystal report where I am passing the values through a dataset from a vb.net form.

My problem is I do not know how to display results when I have more than one value retruned.   An example would be I have 3 rows retruned in the dataset.   The Name, Address,SSN are the same on each line but the Diagnosis is different on each line.

I need to test and see if the Diagnosis in any of these 3 lines equals 96150 or 96152 if it does I can display an x.

I added a formula filed to the report but I will not get a match as I am not sure how to loop through the dataset in crystal report.

********example, I need to add looping so I can test all 3 lines in the dataset
if {tblLkpMHCPDiagnosis.DiagnosisID} = '96150' then
'X'

else

''

Thank you
Avatar of Rajesh Dalmia
Rajesh Dalmia
Flag of India image

add a Group of DiagnosisID. Put your formula in the group header.


rdonline1
Avatar of running32
running32

ASKER

Sorry I'm new to all this.  If I group the DiagnosisID  I will still get 3 rows as the DiagnosisID are different.  The form is layed out as below.   I need to put an X next to either one all or all of them depending on what results are returned so If I get back 96150, 96152 and 96153 in the Diagnosis filed I need to put and X next to each one.   Does this make sense, sorry for being so slow?  Thanks


    96150    H & B Assement   (Neg)
    96152    H & B Asssement (Pos)
    96153    Family Visit with patient
    96154    Family visit without patient  
you have to write one formula as


If {DiagnosisID}  IN (96150,96151,96152) Then
"X"
else
""

then put this formula in your report. If will print X where DiagnosisID will be in a range of 96150 and 96152



rdonline1
I agree, thanks, but my problem is that it will read what is in the first row of the dataset but not what is in the 2nd row.

How can I get the formula to loop through the rows in the dataset and test.  Thank you for sticking with me on this one. :-)

thanks
CR can not read all values at the begining. Unless you loop through all the details it can't pick the values. You can put one Initilize formula at the report header and put another formula in the detail section which will check the values, depending on the checking do some variable updation and at the report footer print the variable or whatever you want.

Wen the CR is printing the 1st record, it can't read the 2 row value unless it loops through that record


rdonline1
Hi running 32.  What rdonline just wrote is somewhat accurate but there is a way to do it.  Generally what you would do is create a subreport that reads through all of the records and at the end of them displays the X (or whatever) so that you'll actually have your subreport loopoing through all of the appropriate records and causing the display on your main report.

My question to you is where do you want to display this X?  Perhaps if you can type a quick illustration of what you want the report to look like?  With that I can give you more specific instructions if you need them.

frodoman
Thank guys.

I start with a dataset that gives me the name, address and Diagnosis of a person.  I tied the dataset to the report and added the database fields to the report for name etc.  My problem is that when I add the {tblLkpMHCPDiagnosis.Diagnosis} field to the report it displays the first record.  What I need to do is test {tblLkpMHCPDiagnosis.Diagnosis} to see if it is equal to 96150 etc and put an x in the box.

Hope I am making sense.
Thanks


The form is set up

Name
Address
City                               State                    Zip
Income Rating

Diagnosis  1.
                2.
                3.


*** is where I would put the X if one of the rows returned matched.

   Health and Behavior Services
   ***     96150    H & B Assement   (Neg)
   ***     96152    H & B Asssement (Pos)
   ***     96153    Family Visit with patient
   ***     96154    Family visit without patient

ASKER CERTIFIED SOLUTION
Avatar of frodoman
frodoman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
On on my report I have just one diagnosis code appearing, which is the first record.  It is not displaying the 2nd Diagnosis id.  Only the 317 diagnosis is showing up.  I don't know how to display the 90853 as it is in the 2nd row of the dataset.   Thanks

my dataset looks like
Fname   LName   Street                City         Zip        Diagnosis
test       Person   123 test street    Test         11234   317
test       Person   123 test street    Test         11234   90853
How is your report set up?  What section of the report do you have Diagnosis field in?
I have the Diagnosis filed in my details section.
I put the //@updateformula in the detail section next to the box 96150.  It shows 0.00 in the box not an X.  

Thanks again for your help.
Sorry, I forgot that you should suppress the formula so it isn't visible.  The idea is that the formula in the group footer would actually display the X.
the field is a varchar 12 in the sql database.  It is never get a match so  shared numberVar IsFound := 1;

the results show 96150 but it wants me to put a string '96150' in the query.

thanks
You can convert from string to number or vice-versa using cdbl or cstr functions.
Do you mean in cyrstal?
I guess you did sorry, I'm loosing my mind over this problem.
Thank you for your help