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

Dynamic Conditional Formatting

Status
Not open for further replies.

jedownsjr

IS-IT--Management
Jun 2, 2003
121
US
Can anyone suggest a way to generate conditionally formatting in a Crystal Report similar to the way you might generate a table dynamically in HTML? What I've got is many text fields in a matrix-style row & column arrangement on the report canvas. Each of these many text fields needs a conditional formatting formula like "IF varValue1=" & varValue1 & "THEN ... END IF" that is unique, based on results from a database table. If this was HTML code, I would use ASP scripts to run through each database record and concatenate strings & field values to build my table output. Any ideas? Can I somehow build a report like this through some type of code, maybe using the RDC?
 
Conditional formatting is by nature dynamic.....when the condition is met, the formatting is done.....when it is not met, the formatting is not done.....have you not tried entering a formula to do this?

Please tell us EXACTLY what you are trying to do and I am sure we can place you on the right path.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
If you right click any field and select format field then you can use an IF...THEN to conditionally control many formatting options.

As dgillz pointed out, you've shared nothing specific.

Try posting technical information:

Crystal version
Database version
Example data
Expected output

-k
 
Thank you for your replies. Here are some more details -- sorry, this is gonna be long:

1. CR version 8.5.
2. DB is Access for now, SQL Server later, but this question should not be DB-specific -- more general related to building the report.
3. Sample data is very complex, but the 1st field called txtID consists of 6 "parameters" which uniquely define the data. 3rd "parameter" value for this field changes with each series, and other values change as necessary to define the data (notice no two txtID values are identical). Here are 9 sample records:
============= ========= ==========
txtID blnGreen blnRed
============= ========= ==========
AAA_0_0_1_1_0 1 0
BBB_0_0_1_1_0 1 0
CCC_0_0_1_1_0 0 1
... and so on to complete one series
AAA_0_0_2_1_0 1 0
BBB_0_0_2_1_0 1 0
CCC_0_0_2_1_0 1 0
... and so on to complete the 2nd series
AAA_0_0_3_1_0 0 1
BBB_0_1_3_2_0 1 0
CCC_0_2_3_1_0 1 0
... and so on to complete the 3rd series

4. Example Output:

CUSTOMER Series1 Series2 Series3
AAA GREEN GREEN RED
BBB GREEN GREEN GREEN
CCC RED GREEN GREEN

The example output shown here would consist of a matrix made up of text boxes arranged in a grid. The sample data represents records in a single DB table, 3 fields in the table. The 1st field is a unique ID (no value the same), and the other 2 fields are boolean 1 or 0 values to represent whether that record is either green or red. If there is a 1 in the Green column, that record's corresponding text box in the matrix grid will be conditionally formatted with a green background. If the boolean value is 1 in the Red column, then that records'a corresponding text box will be conditionally formatted with a red background. There are >100 records in the DB table, so likewise there will be >100 conditionally formatted text boxes, but the matrix should expand dynamically as the number of records expands. The formula for the 1st cell in the matrix would look something like:
IF txtID="AAA_0_0_1_1_0 " AND blnGreen=1 THEN
crGreen;
IF txtID="AAA_0_0_1_1_0 " AND blnRed=1 THEN
crRed;
For the 1st record, where txtID="AAA_0_0_1_1_0", the blnGreen field has a value of 1, so the 1st IF statement evaluates to TRUE. This will conditionally format the text field's background color to be Green.

I have all of the above already built but here's the part I'm trying to figure out:
Rather than manually edit each cell's conditional formatting formula, is there a way to set the conditional formatting formula dynamically via code or some other vehicle? If I was building a web page with an HTML table dynamically, I would loop through a recordset containing all the records in the table, evaluate each one to determine which color I should set for the cell based on the value in the boolean fields for the record, write out the HTML code for that cell using If/Then or Case/Select to set the background color of the cell, move forward to the next record in the recordset, set it's color the same way, continue until I reached the end of the recordset, then close out my table tags... something like:
"IF txtID=AAA_0_0_1_1_0 AND blnGreen=1 THEN response.write "<td background='green'>" & txtID"
... then I would go to the next record and do the same until I had looped through the entire table and built the matrix complete with color formatting.
I hope this makes sense -- again, sorry so long. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top