473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Conditional Formatting Using If/Then/Else in Report Detail Section

Hello,

I need to create conditional formatting of a text box in the detail section of a report. The formatting is based on multiple parameters that are stored in a query. For example, pretend that [Census3] = 50%, [Yellow] = 80%, and [Green] = 90%. I will check [PercentCensus] in the report against [Census3] (from the query, but currently stored in a text box on the report via a Dlookup - textbox name is still [Census3]). If [PercentCensus] is less than [Census3] then I want to compare the value of [PercentRevenue] (another report text box) against [Yellow3] and [Green3] to find the appropriate background color. In this case, [Yellow3]=[Yellow]*[Census3] - or 40%.

if [PercentCensus] is > than [Census3] I will compare against [Census2], and so on.

Basically, I am reducing the threshold that my [PercentRevenue] needs to meet in order to be yellow or green if the [PercentCensus] value is below a certain threshold.

Below is the code I currently have. I am using the same code for the Report Footer (just different text box names) section and it works perfectly. Being that this is a report, the number of rows in the detail section always changes based on the filters used to run it. I'm finding that with this code, it always uses the lowest value in the detail section when comparing against the thresholds.

Is there a better way to conditionally format the detail section when you have multiple layers of criteria to meet. Any help would be much appreciated.


---------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Load()
  2.  
  3. If Me![PercentCensus] < Me![Census3] Then
  4.         If Me![PercentRevenue] < Me![Yellow3] Then
  5.             Me![PercentRevenue].BackColor = vbRed
  6.         Else
  7.        If Me![PercentRevenue] < Me![Green3] Then
  8.             Me![PercentRevenue].BackColor = vbYellow
  9.         Else
  10.             Me![PercentRevenue].BackColor = vbGreen
  11.         End If
  12.         End If
  13. Else
  14. If Me![PercentCensus] < Me![Census2] Then
  15.         If Me![PercentRevenue] < Me![Yellow2] Then
  16.             Me![PercentRevenue].BackColor = vbRed
  17.         Else
  18.        If Me![PercentRevenue] < Me![green2] Then
  19.             Me![PercentRevenue].BackColor = vbYellow
  20.         Else
  21.             Me![PercentRevenue].BackColor = vbGreen
  22.         End If
  23.         End If
  24. Else
  25. If Me![PercentCensus] < Me![Census1] Then
  26.        If Me![PercentRevenue] < Me![Yellow1] Then
  27.         Me![PercentRevenue].BackColor = vbRed
  28.         Else
  29.        If Me![PercentRevenue] < Me![Green1] Then
  30.             Me![PercentRevenue].BackColor = vbYellow
  31.         Else
  32.             Me![PercentRevenue].BackColor = vbGreen
  33.         End If
  34.         End If
  35. Else
  36. If Me![PercentCensus] >= Me![Census1] Then
  37.        If Me![PercentRevenue] < Me![Yellow] Then
  38.         Me![PercentRevenue].BackColor = vbRed
  39.         Else
  40.        If Me![PercentRevenue] < Me![Green] Then
  41.             Me![PercentRevenue].BackColor = vbYellow
  42.         Else
  43.             Me![PercentRevenue].BackColor = vbGreen
  44.         End If
  45.         End If
  46. End If
  47. End If
  48. End If
  49. End If
  50.  
  51. End Sub
  52.  
  53.  
Sep 23 '10 #1
2 4426
TheSmileyCoder
2,322 Expert Mod 2GB
What you have displayed formats the entire report. Is taht what you want? Or do you want "per detail" formatting?

Are you criteria stored in a table? If so how does that table look? If not how is the details of the different Percentage threshold stored?
Sep 24 '10 #2
I need it to be for each line of detail - I can't figure that part out.

My criteria are stored in textboxes on the report (with visible=no). The texboxes are Dlookups to a query, which pulls from a table but adds some calculations.

Table Fields
tbl_Project_Setup:
[Revenue % Yellow Threshold]
[Revenue % Green Threshold]
[Census % Normal Rev Threshold]
[Census % Reduced Rev Threshold Level One]
[Census % Reduced Rev Threshold Level Two]

Query Feilds-
qsel_Thresholds_for_Summary_Report:
Yellow: Revenue % Yellow Threshold
Green: Revenue % Green Threshold
Census1: Census % Normal Rev Threshold
Census2: Census % Reduced Rev Threshold Level One
Census3: Census % Reduced Rev Threshold Level Two
Yellow1: [Revenue % Yellow Threshold]*[Census % Normal Rev Threshold]
Yellow2: [Revenue % Yellow Threshold]*[Census % Reduced Rev Threshold Level One]
Yellow3: [Revenue % Yellow Threshold]*[Census % Reduced Rev Threshold Level Two]
Green1: [Revenue % Green Threshold]*[Census % Normal Rev Threshold]
Green2: [Revenue % Green Threshold]*[Census % Reduced Rev Threshold Level One]
Green3: [Revenue % Green Threshold]*[Census % Reduced Rev Threshold Level Two]

My Dlookups on the report are straight forward, for example: =DLookUp("[Yellow]","qsel_Thresholds_for_Summary_Report","[ID]=[SetupID]")

[SetupID] is a constant set to 1 - so it finds the record in the query with ID = 1. I could have done the Dlookups in VBA (and did actually try it), but it's just messier to me.
Sep 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alex | last post by:
Is it possible to set conditional formatting using code in a module? Thanks for your help Alex
1
by: John | last post by:
My report is based off of a table. I need a record on the report to be highlighted if that record ID is in a different table. Something like, if record ID exists in Query X, then conditional format...
3
by: Melissa | last post by:
What specifically causes the Format event of a report's section to fire? Thanks! Melissa
2
by: Von Bailey | last post by:
I have a form where the conditional formatting is set on some fields to bold if certain conditions are met. However, when the conditions are met some of the data that is to bold is either not...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
0
by: Tim Marshall | last post by:
Access 2003. A report of mine was hanging on print preview. It turned out the issue was a bound text box where the data was too big to fit all on one page. When I changed the "keep together"...
10
by: sara | last post by:
Hi - Is it possible to hide the detail section of a report at run time? I have a report that prints all details, with summary lines. The user would like the report ALSO with just summary lines....
7
by: NJonge01 | last post by:
Hi, I'd like to produce a report that basically looks like an excel printout. Description: Profile Print Report Detail Section with 3 bordered text boxes all text boxes are 'abutted'...
4
by: Trish | last post by:
Hello All and thanks in advance for your help. The code below works just fine in the Print event of the report Detail section. Is it possible to condense it using a loop or something? Can you...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.