473,394 Members | 1,700 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.

How to Set Dynamic Conditional Formating on Reports

132 100+
Hi all!
I have a Report from Cross-Tab Query in which I would like to Highlight the Whole Columns conditionally (Details Sections) according to the certain prio-conditions.
The fields are: Field1, Field2, Field3, Field4, Field5...Field30.

I have tried to set the Conditional Formatting for Each Fields as on the Details Section of the ReportDesinView. On the Property Sheet of a Report, I have selected the DetailsSection and then Set the On Paint Property the following Code!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Paint()
  2. If Me!Field1.Value<175 Then
  3. Me!Field1.BackColor = vbBlack
  4. End If
  5. If Me!Field2.Value < 175 Then
  6. Me!Field2.BackColor = vbBlack
  7. End If
  8. ...
  9. End Sub
  10.  
Entering all fieldNames and Conditions, all values <175 would be highlighted as expected!
QUESTION:
How to set this Conditional Formatting Dynamic, wont depends on FieldNames.
ie. I want to use the same code to apply to different fieldnames say FieldN0,FieldN1,FieldN2,FieldN3 ... Without explicity Entering fieldNames
Jul 26 '11 #1

✓ answered by NeoPa

Not only is your posted solution not even correct, it is only the result of following some already clear instructions. Awarding that a Best Answer is an abuse of the forum and is not acceptable. See below how it should look, and award the Best Answer only to post #2 where the answer you tried to implement was given.

Expand|Select|Wrap|Line Numbers
  1. For Each ctlO In Me.Controls
  2.     With ctlO
  3.         If Left(.Name) = "Field" Then _
  4.             .BackColor = IIf(.Value < 175, vbBlack, {Original colour})
  5.     End With
  6. Next ctlO
I don't know what your original background colour is, but it needs to be reset any time the value isn't less than 175, otherwise they will all tend to end up as black over time and multiple records.

10 3643
Rabbit
12,516 Expert Mod 8TB
You could use a for each construct to iterate through all the fields. Also, please don't double post your questions.
Jul 26 '11 #2
Mr Key
132 100+
Ok thanks! But How can it be done?
Rabbit?
Jul 26 '11 #3
Rabbit
12,516 Expert Mod 8TB
I already said how it can be done. By using "a for each construct to iterate through all the fields."

You could iterate through your controls if you wanted, but that could pull in controls you don't want. By iterating through the fields, assuming the control has the same name, then you can rest assured that it will only format the fields in the recordset.
Jul 26 '11 #4
Mr Key
132 100+
Give me the code`s example please!
I have suffered a lot to write the code by explicitly writing down the field names.
Please!
Jul 26 '11 #5
Rabbit
12,516 Expert Mod 8TB
We don't give out code here unless an effort has been shown by the poster that they attempted to code it themselves.

When you have done so, you can post the code you tried and we can work through the errors.
Jul 26 '11 #6
Mr Key
132 100+
OK!!
I have tried this!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Paint()
  2. Dim MyDB As DAO.Database
  3. Dim rstSource As DAO.Recordset
  4. Dim inFldCtr As Integer
  5. Set MyDB = CurrentDb()
  6. Set rstSource = MyDB.OpenRecordset(strSource)
  7. rstSource.MoveLast: rstSource.MoveFirst
  8. For inFldCtr = 0 To .Fields.Count - 1
  9. If .Fields(inFldCtr).Name.Value > 175 Then
  10. .Fields(inFldCtr).Name.BackColor = vbBlack
  11. End If
  12. Next inFldCtr
  13. End Sub
  14.  
  15.  
But this code couldnt work!
Please help!!!!
Jul 27 '11 #7
Mr Key
132 100+
Expand|Select|Wrap|Line Numbers
  1. For Each ctlo In Me.Controls
  2. ctlo.BackColor=VbBlack
Aug 11 '11 #8
NeoPa
32,556 Expert Mod 16PB
Not only is your posted solution not even correct, it is only the result of following some already clear instructions. Awarding that a Best Answer is an abuse of the forum and is not acceptable. See below how it should look, and award the Best Answer only to post #2 where the answer you tried to implement was given.

Expand|Select|Wrap|Line Numbers
  1. For Each ctlO In Me.Controls
  2.     With ctlO
  3.         If Left(.Name) = "Field" Then _
  4.             .BackColor = IIf(.Value < 175, vbBlack, {Original colour})
  5.     End With
  6. Next ctlO
I don't know what your original background colour is, but it needs to be reset any time the value isn't less than 175, otherwise they will all tend to end up as black over time and multiple records.
Aug 11 '11 #9
Rabbit
12,516 Expert Mod 8TB
Sorry, I dropped the ball on this one. I didn't see the post from 2 weeks ago.
Aug 11 '11 #10
Mr Key
132 100+
Yap! you are Correct Neopa!
What I have writen is just a brief answer of what was supposed to be.
Thanks all for your contributions
Aug 12 '11 #11

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

Similar topics

2
by: rudy | last post by:
I am trying to highlight the output of a field to display something similar to conditional formating. Would prefer to display the result with a code instead of a colored font or colored background...
3
by: Tom | last post by:
Is there any way to use conditional formating to change a control for a field in a continuous form to a textbox, option group or combobox depending on the value of another field on the form? On a...
1
by: Marius | last post by:
I would like to format each row in a listbox (VBA - Access) according to a condition found on the same row. i.e: I want to grey-out all the customers called "John". Can this be done, for I have...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
1
by: OxfordConsult | last post by:
I have a form in which a selection in a list box pulls a record to be displayed in a subform. All contacts are categorised as either Active, Inactive, or left company. I was wondering if it is...
2
by: FNA access | last post by:
I have a request to highlight any entries in a report that have the same date. The report is sorted by date so the records would be one after the other. I cannot find any events for the report that...
6
by: sphinney | last post by:
I'm trying to change the font color of a textbox on a report to red if the date displayed in the textbox is before today. I'm using the following code to accomplish this: Dim Ctrl1 as Textbox...
1
by: Earl Anderson | last post by:
A business colleague and I are collaborating 'long distance' on an applet for work. He is doing the programming and I am doing the business process form design. We had discussed my desire to make...
1
by: gtslabs | last post by:
I have a report with 2 subreports The first subreport has 3 fields (Expr1, Field1, Field2) Where Expr1 is a Date I want to highlight the 3 fields if a date is within a range of 2 dates. I was...
7
gnawoncents
by: gnawoncents | last post by:
I have a datasheet with alternate row shading and conditional formatting. Unfortunately when the conditional formatting returns true, I lose the alternate row shading for that control. Has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.