469,312 Members | 2,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Conditional Formatting ?

Can someone please guide me an easy way of having more than three conditional formatting conditions?
Apr 16 '07 #1
12 7302
ADezii
8,800 Expert 8TB
Can someone please guide me an easy way of having more than three conditional formatting conditions?
I'm afraid that you will have to take the code route for that. Here is a simple example based on a Postal Code Field (txtPostalCode) on a Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Select Case Me![txtPostalCode]
  3.   Case 98105
  4.     Me![txtPostalCode].ForeColor = QBColor(2)
  5.     Me![txtPostalCode].FontBold = True
  6.     Me![txtPostalCode].FontUnderline = False
  7.   Case 98122
  8.     Me![txtPostalCode].ForeColor = vbBlue
  9.     Me![txtPostalCode].FontBold = False
  10.     Me![txtPostalCode].FontUnderline = True
  11.   Case 98401
  12.     Me![txtPostalCode].ForeColor = QBColor(4)
  13.     Me![txtPostalCode].FontBold = True
  14.     Me![txtPostalCode].FontUnderline = False
  15.   Case 98033
  16.     Me![txtPostalCode].ForeColor = QBColor(3)
  17.     Me![txtPostalCode].FontBold = True
  18.     Me![txtPostalCode].FontUnderline = False
  19.   Case Else
  20.     Me![txtPostalCode].ForeColor = 0
  21.     Me![txtPostalCode].FontBold = False
  22.     Me![txtPostalCode].FontUnderline = False
  23. End Select
  24. End Sub
Apr 16 '07 #2
I'm afraid that you will have to take the code route for that. Here is a simple example based on a Postal Code Field (txtPostalCode) on a Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. Select Case Me![txtPostalCode]
  3.   Case 98105
  4.     Me![txtPostalCode].ForeColor = QBColor(2)
  5.     Me![txtPostalCode].FontBold = True
  6.     Me![txtPostalCode].FontUnderline = False
  7.   Case 98122
  8.     Me![txtPostalCode].ForeColor = vbBlue
  9.     Me![txtPostalCode].FontBold = False
  10.     Me![txtPostalCode].FontUnderline = True
  11.   Case 98401
  12.     Me![txtPostalCode].ForeColor = QBColor(4)
  13.     Me![txtPostalCode].FontBold = True
  14.     Me![txtPostalCode].FontUnderline = False
  15.   Case 98033
  16.     Me![txtPostalCode].ForeColor = QBColor(3)
  17.     Me![txtPostalCode].FontBold = True
  18.     Me![txtPostalCode].FontUnderline = False
  19.   Case Else
  20.     Me![txtPostalCode].ForeColor = 0
  21.     Me![txtPostalCode].FontBold = False
  22.     Me![txtPostalCode].FontUnderline = False
  23. End Select
  24. End Sub
How do i get here, and how & where to write a code ?
Apr 16 '07 #3
ADezii
8,800 Expert 8TB
How do i get here, and how & where to write a code ?
The code would be written in the Form's Current() Event as indicated so that it may reflect different States for each Record.
Apr 16 '07 #4
The code would be written in the Form's Current() Event as indicated so that it may reflect different States for each Record.
I am trying to do the conditional formatting in a report where i have added some other sub reports aswell, so how do i write the code for tht now?
Apr 17 '07 #5
ADezii
8,800 Expert 8TB
I am trying to do the conditional formatting in a report where i have added some other sub reports aswell, so how do i write the code for tht now?
In the Report's Detail Section, Format() Event as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2. Select Case Me![Title]
  3.   Case "Sir"
  4.     Me![Title].FontWeight = Bold
  5.     Me![Title].FontSize = 12
  6.     Me![Title].FontUnderline = False
  7.     Me![Title].BorderStyle = 1
  8.   Case "Mr."
  9.     Me![Title].FontWeight = Bold
  10.     Me![Title].FontSize = 10
  11.     Me![Title].FontUnderline = True
  12.     Me![Title].BorderStyle = 0
  13.   Case "Dude"
  14.     Me![Title].FontWeight = Normal
  15.     Me![Title].FontSize = 12
  16.     Me![Title].FontUnderline = True
  17.     Me![Title].BorderStyle = 0
  18.   Case Else
  19.     Me![Title].FontWeight = Normal
  20.     Me![Title].FontSize = 8
  21.     Me![Title].FontUnderline = False
  22.     Me![Title].BorderStyle = 0
  23. End Select
Apr 17 '07 #6
Can you please tell in more detail as to how can i get it done, actually i am new to access DB and dont know a lot of stuff.

I tried as desribed in your last post but i could not find the format () Event in report's detail section.

Thanks,
Apr 17 '07 #7
ADezii
8,800 Expert 8TB
Can you please tell in more detail as to how can i get it done, actually i am new to access DB and dont know a lot of stuff.

I tried as desribed in your last post but i could not find the format () Event in report's detail section.

Thanks,
  1. Select your Report inh the Database Window
  2. Click on Design
  3. Double Click on the Detail Section (between Page Header and Page Footer)
  4. Click on Format
  5. Click on the Build (...) button
  6. Select Code builder
  7. Click on OK
  8. Copy and Paste the code in this Event (Format())
Apr 17 '07 #8
Thanks i got it right till here, but now since i have report with sub reports and each field had conditional formatting ,

First of all, can i look at the code for the three conditions i wrote , so that i get an e.g. of how to build the code.

Secondly, how do i do the conditional formatting for each and every single field?

For e.g. I have moisture values which should be green if its in the range 2.35 - 3.25 and then yellow if its less than 2.35 - 2.10 and yellow again if it is greater than 3.25-3.50. And red if it is less than 2.10 and greater than 3.5.
Apr 18 '07 #9
ADezii
8,800 Expert 8TB
Thanks i got it right till here, but now since i have report with sub reports and each field had conditional formatting ,

First of all, can i look at the code for the three conditions i wrote , so that i get an e.g. of how to build the code.

Secondly, how do i do the conditional formatting for each and every single field?

For e.g. I have moisture values which should be green if its in the range 2.35 - 3.25 and then yellow if its less than 2.35 - 2.10 and yellow again if it is greater than 3.25-3.50. And red if it is less than 2.10 and greater than 3.5.
Here is a Code Templqate:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me![txtRange]
  2.   Case Is > 3.5
  3.      Me![txtMoisture Values].ForeColor = vbRed
  4.   Case 2.35 To 3.5
  5.      Me![txtMoisture Values].ForeColor = vbGreen
  6.   Case 2.10 To 2.34
  7.      Me![txtMoisture Values].ForeColor = vbYellow
  8.   Case Is < 2.1
  9.      Me![txtMoisture Values].ForeColor = vbRed
  10.   Case Else
  11.      Me![txtMoisture Values].ForeColor = vbBlack
  12. End Select
Apr 18 '07 #10
Here is a Code Templqate:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me![txtRange]
  2.   Case Is > 3.5
  3.      Me![txtMoisture Values].ForeColor = vbRed
  4.   Case 2.35 To 3.5
  5.      Me![txtMoisture Values].ForeColor = vbGreen
  6.   Case 2.10 To 2.34
  7.      Me![txtMoisture Values].ForeColor = vbYellow
  8.   Case Is < 2.1
  9.      Me![txtMoisture Values].ForeColor = vbRed
  10.   Case Else
  11.      Me![txtMoisture Values].ForeColor = vbBlack
  12. End Select
How do i enter this format now, i opened the detail column and it doesnt show me correctly the build property, since i have seven different fields like moisture, temperature, GS, Compactibility etc. and all have different values, so what should i do now??
Apr 18 '07 #11
I could do this successfully but its asking me for the txtrange, what should i enter here?
May 14 '07 #12
it gives me runtime error '2465' that it cant determine the txtrange?
May 14 '07 #13

Post your reply

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

Similar topics

4 posts views Thread by Bradley | last post: by
8 posts views Thread by Dimitri Furman | last post: by
2 posts views Thread by Von Bailey | last post: by
5 posts views Thread by Andrew Chanter | last post: by
1 post views Thread by GGerard | last post: by
2 posts views Thread by Filips Benoit | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.