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