PDA

View Full Version : Conditional BackColor Code Needed



talere12
11-28-2006, 06:56 AM
I am creating a report based on a union query. The first query in the union contains a Department field and the number of employees by department. The second query contains the sum of all the departments. I have unified the two queries and have ordered the results. What I am trying to do now is have the "Totals" section (which is included in the Department field) shade with a background color of yellow. I want all other Department names to remain white. I could have just created the report without the Union and manually changed the BackColor in the totals query, but I figured there has to be a way to accomplish this through VBA. I have tried many different variations of VBA code but have been unsuccessful in accomplishing this. Below is an example of the code that I have tried.

Private Sub Report_Current()
If Me.Department = "Totals" Then
Detail.BackColor = 8454143
Else
Detail.BackColor = 1677215
End If

End Sub

Can someone tell me if there is a way to get this to work???:dunno

OBP
11-28-2006, 07:15 AM
The reason that it doesn't work is that you need to put the code in the Report's Detail "On Format" event procedure.
To find the Detail's Event procedures click on the "bar" that seperates the Header or Group Header from the detail section.
You can also use normal "Conditional Formatting" in the field itself if the conditions are fairly simple. Click on the field and then on the Main Menu>Format Conditional Formatting

talere12
11-28-2006, 11:12 AM
Thanks for the feedback! It worked perfect!!