Color Formatting Report

andthe

New Member
Joined
Sep 26, 2003
Messages
25
I'm using a form to populate a report. If a specific field on the form is set to true, I want a portion on the report grayed out (i.e. the 'back color' changed to gray). If the answer is to use VB, can you please be as specific as possible as I don't know VB. Thanks!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
In the absence of field names, I'll provide an example using one of my own projects. In this case, I am looking for "20" in a field called [verse desc]. If it occurs, I want [verse body] to have a grey background:

Code:
  If InStr(1, [Verse desc], "20") > 1 Then
    [verse body].BackColor = RGB(196, 196, 196)
    [verse body].BackStyle = 1
  Else
    [verse body].BackColor = 16777215
    [verse body].BackStyle = 1
  End If

To use, go to your report in Design View. Right-click the Detail header and select Properties.
Go to the Event tab and double-click the blank line for Format. You'll see [Event Procedure]. Click the builder (...) button on that line and you'll be in the code window. In the blank line between Sub... and End Sub, post the code above.
Changes that you'll need to make:
1. Change the field names (in square brackets) to suit.
2. The condition (the If line) will need to be changed to something like:
If [MyField] = -1 Then '-1 is TRUE, 0 is FALSE
3. To change the grey colour, play with the RGB values. ANY RGB with the same Red, Green and Blue values will give you grey. Higher numbers are lighter grey -- RGB(255, 255, 255) is white and RGB(0, 0, 0) is black.
The BackStyle value has to be there, otherwise the control is transparent and the background colour will not be seen.

Note: If you want the whole line to be filled with a grey background, use this instead:

Code:
  If InStr(1, [Verse desc], "20") > 1 Then
    Detail.BackColor = RGB(196, 196, 196)
  Else
    Detail.BackColor = 16777215 'white
  End If
Denis
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,242
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top