473,405 Members | 2,310 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,405 software developers and data experts.

Sorting in a Report by Color

I have a report in Access that gives the average score by skill that each teacher received.

For instance, in the body of the report I have Skill, TotalPointsPossible, TeacherAverage.

I have some VBA programming in the formatting of the detail that colors the background of the TeacherAverage based on the results, so if the TeacherAverage is between 1 and 10 the background color is red. If the TeacherAverage is between 10.1 and 20, the background color is yellow, and if the TeacherAverage is betwwn 20.1 and 30, the background color is green.

How can I then sort the body of the detail by color, so that all the red averages show up first, then yellow, then green.

Is this possible?

Thank you.
Jul 10 '07 #1
5 3768
puppydogbuddy
1,923 Expert 1GB
I have a report in Access that gives the average score by skill that each teacher received.

For instance, in the body of the report I have Skill, TotalPointsPossible, TeacherAverage.

I have some VBA programming in the formatting of the detail that colors the background of the TeacherAverage based on the results, so if the TeacherAverage is between 1 and 10 the background color is red. If the TeacherAverage is between 10.1 and 20, the background color is yellow, and if the TeacherAverage is betwwn 20.1 and 30, the background color is green.

How can I then sort the body of the detail by color, so that all the red averages show up first, then yellow, then green.

Is this possible?
Thank you.
I don't believe you can order by color directly, but you can accomplish the same end result with this>>>>>> Order By TeacherAverage.

You did not post any code, so I'm assuming that you know where to insert the Order By clause. If you have any problems, let me know.
Jul 10 '07 #2
I don't believe you can order by color directly, but you can accomplish the same end result with this>>>>>> Order By TeacherAverage.

You did not post any code, so I'm assuming that you know where to insert the Order By clause. If you have any problems, let me know.
One thing I didn't put in my post is the color coding is based on the total points possible and the teacher averages. So, if a skill has a TotalPointsPossible of 30, then the color coding would be red if the TeacherAverage was between 1 and 10, yellow if the TeacherAverage was between 10.1 and 20, and green if the TeacherAverage was between 20.1 and 30. Then if another skill has a TotalPointsPossible of 20, then the color coding would be red if the TeacherAverage was between 1 and 7, yellow if the TeacherAverae was between 7.1 and 14, and green if the TeacherAverage was between 14.1 and 20. So I can't just sort by the TeacherAverage. I know that somehow I need to assign the background colors with a value and sort by that value, but I just don't know how to go about it or where to put it. Any help would be appreciated.

This is the code that I am using the in the On Format Event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![TotalPointsPossible] = 30 And Me![Average] >= 1 And Me![Average] <= 10 Then
Me.Average.BackColor = vbRed
ElseIf Me![TotalPointsPossible] = 30 And Me![Average] >= 10.1 And Me![Average] <= 20 Then
Me.Average.BackColor = vbYellow
ElseIf Me![TotalPointsPossible] = 30 And Me![Average] >= 20.1 And Me![Average] <= 30 Then
Me.Average.BackColor = vbGreen
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 1 And Me![Average] <= 7 Then
Me.Average.BackColor = vbRed
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 7.1 And Me![Average] <= 14 Then
Me.Average.BackColor = vbYellow
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 14.1 And Me![Average] <= 20 Then
Me.Average.BackColor = vbGreen
Else
Me.Average.BackColor = vbWhite
End If
Jul 11 '07 #3
puppydogbuddy
1,923 Expert 1GB
One thing I didn't put in my post is the color coding is based on the total points possible and the teacher averages. So, if a skill has a TotalPointsPossible of 30, then the color coding would be red if the TeacherAverage was between 1 and 10, yellow if the TeacherAverage was between 10.1 and 20, and green if the TeacherAverage was between 20.1 and 30. Then if another skill has a TotalPointsPossible of 20, then the color coding would be red if the TeacherAverage was between 1 and 7, yellow if the TeacherAverae was between 7.1 and 14, and green if the TeacherAverage was between 14.1 and 20. So I can't just sort by the TeacherAverage. I know that somehow I need to assign the background colors with a value and sort by that value, but I just don't know how to go about it or where to put it. Any help would be appreciated.

This is the code that I am using the in the On Format Event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![TotalPointsPossible] = 30 And Me![Average] >= 1 And Me![Average] <= 10 Then
Me.Average.BackColor = vbRed
ElseIf Me![TotalPointsPossible] = 30 And Me![Average] >= 10.1 And Me![Average] <= 20 Then
Me.Average.BackColor = vbYellow
ElseIf Me![TotalPointsPossible] = 30 And Me![Average] >= 20.1 And Me![Average] <= 30 Then
Me.Average.BackColor = vbGreen
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 1 And Me![Average] <= 7 Then
Me.Average.BackColor = vbRed
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 7.1 And Me![Average] <= 14 Then
Me.Average.BackColor = vbYellow
ElseIf Me![TotalPointsPossible] = 20 And Me![Average] >= 14.1 And Me![Average] <= 20 Then
Me.Average.BackColor = vbGreen
Else
Me.Average.BackColor = vbWhite
End If
I can't find any documented examples that do what you want. Maybe one of the following methods might work. Have not tested and do not know if BackColor property is exposed to grouping/sorting routines. Let me know what happens if you try it. If "Average.BackColor" does not work, try "Average" & .BackColor
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. Me.GroupLevel(0).ControlSource = "Average.BackColor"
  4.  
  5. End sub
  6.  
  7. Or this:
  8.  
  9. Private Sub Report_Open(Cancel As Integer)
  10.  
  11. Me.OrderBy = "Average.BackColor"
  12.  
  13. Me.OrderByOn = True
  14.  
  15. End Sub
  16.  
Jul 13 '07 #4
I can't find any documented examples that do what you want. Maybe one of the following methods might work. Have not tested and do not know if BackColor property is exposed to grouping/sorting routines. Let me know what happens if you try it. If "Average.BackColor" does not work, try "Average" & .BackColor
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. Me.GroupLevel(0).ControlSource = "Average.BackColor"
  4.  
  5. End sub
  6.  
  7. Or this:
  8.  
  9. Private Sub Report_Open(Cancel As Integer)
  10.  
  11. Me.OrderBy = "Average.BackColor"
  12.  
  13. Me.OrderByOn = True
  14.  
  15. End Sub
  16.  
I tried both and neither worked. The first option you gave me came back with error message "CALC expression (Average.BackColor) is invalid". If I changed it to "Average" & .BackColor it told me "Compile error: Invalid or unqualified reference" The second option gave me the error message "Column (BackColor) was used in a CALC expression but is not defined in the rowset"
Jul 13 '07 #5
puppydogbuddy
1,923 Expert 1GB
I tried both and neither worked. The first option you gave me came back with error message "CALC expression (Average.BackColor) is invalid". If I changed it to "Average" & .BackColor it told me "Compile error: Invalid or unqualified reference" The second option gave me the error message "Column (BackColor) was used in a CALC expression but is not defined in the rowset"

Jag Girl,
OK, that pretty well establishes that you can't order your data using field properties and BackColor is a field property.

What you can do is create an alias column (see below) in your source query that assigns a row value in the alias column, and then you will be able to sort on the alias column:

ColorRank: IIf(([TotalPointsPossible] = 30 And [Average] Between 1 And 10) Or ([TotalPointsPossible] = 20 And [Average] Between 1 And 7), “Red”, IIf(([TotalPointsPossible] = 30 And [Average] Between 10.1 And 20) Or ([TotalPointsPossible] = 20 And [Average] Between 7.1 And 10), “Yellow”, IIf(([TotalPointsPossible] = 30 And [Average] Between 20.1 And 30) Or ([TotalPointsPossible] = 20 And [Average] Between 14.1 And 20), “Green”, “White”)))

Once you have the above column in your Query, then you can order by ColorRank in the open event of your report as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. Me.OrderBy = "ColorRank"
  4.  
  5. Me.OrderByOn = True
  6.  
  7. End Sub
  8.  
Jul 14 '07 #6

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

Similar topics

2
by: Jur Schagen | last post by:
I have this weird sorting problem. I have a report that is based on a query. The query is sorted on field A, and if I run it seperately it is decently sorted on that field. However, if I call the...
3
by: Mat N | last post by:
Hi, I've been trying to work out how to create a report based on crosstab query for which the number of fields is variable. For example in a situation where you show customer billing by year in...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
4
by: Marie | last post by:
My report has a text field named ItemNum. Most records have a value for ItemNum. I set Grouping And Sorting to sort ascending on the ItemNum field. The records where ItemNum is Null appear at the...
5
by: Mike | last post by:
Hello All, I have a report based upon a query. I have added a control to report footer that calcs the total cost of the inventory: =SUM(). When this total calculation is NOT on the report,...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
8
by: nn0410 | last post by:
I have a report whose record source is a query. The query includes an ORDER BY clause that sorts on a particular set of columns. I would like to be able to run the same report with the same input...
3
by: Don | last post by:
I have a "Report" that is created from a "Form". It prints a list of items, you may consider it a shopping list. In any event I use to run this in alphabetical order but have since decided to run...
8
by: sara | last post by:
Hi - I have looked at all posts and tried both Allen Browne's Report Sorting at run Time ( Select Case Forms!frmChooseSort!grpSort Case 1 'Name Me.GroupLevel(0).ControlSource = "LastName"...
5
by: saran3b2 | last post by:
Hi all, If u know the solution please suggest me. I need these urgent. production.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="xsl/vinoth-new.xsl"?>...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.