In the form below I want to colour each row depending on the content of the "Notes" field.
If I use conditional formatting in multiple mode, after a few rules the formatting of the notes field disappears.
I have tagged the controls to respond to code but the entire column is coloured.
Clicking anywhere on a record will change the colour but again the entire column is changed.
I have tried using a dummy field to mirror the id field, "Accession Number" in the on current event to no avail.
I know I can do this with conditional formatting but it sees that each control will need multiple rules to work correctly.
It also means hours of work to change any one colour.
All controls in the detail area are bound.
How do I modify my code to make it work?
If I use conditional formatting in multiple mode, after a few rules the formatting of the notes field disappears.
I have tagged the controls to respond to code but the entire column is coloured.
Clicking anywhere on a record will change the colour but again the entire column is changed.
I have tried using a dummy field to mirror the id field, "Accession Number" in the on current event to no avail.
I know I can do this with conditional formatting but it sees that each control will need multiple rules to work correctly.
It also means hours of work to change any one colour.
All controls in the detail area are bound.
How do I modify my code to make it work?
Code:
Private Sub Form_Current()
Me.txtSelect = Me.txtAccess 'this has no effect
setColours Nz(Me.txtNotes, ""), Me
Me.txtSelect = Me.txtAccess
End Sub
Code:
Public Sub setColours(sStr As String, frm As Form)
Dim R As Integer
Dim G As Integer
Dim B As Integer
Dim str As String
Dim ctl As Control
R = 240 ' default colour if "Notes" is null
G = 240
B = 240
Select Case sStr
Case "boxes":
R = 230
G = 192
B = 228
str = "BO"
Case "Location":
R = 230
G = 192
B = 228
str = "BO"
Case "No Data":
R = 218
G = 138
B = 151
str = "ND"
Case "Double":
R = 159
G = 211
B = 225
str = "DO"
Case "Duplicate":
R = 157
G = 245
B = 172
str = "DU"
Case "Original":
R = 209
G = 234
B = 240
str = "OR"
Case "No Match":
R = 225
G = 204
B = 75
str = "MA"
Case "No Raw":
R = 212
G = 150
B = 148
str = "RA"
Case "No Jpg":
R = 229
G = 190
B = 189
str = "JP"
Case "Spelling":
R = 255
G = 255
B = 255
str = "SP"
End Select
With frm
For Each ctl In .Section(acDetail).Controls
ctl.BackColor = RGB(240, 240, 240)
ctl.ForeColor = RGB(0, 0, 0)
If ctl.ControlType = acTextBox Then
If InStr(ctl.Tag, str) > 0 Then
ctl.BackColor = RGB(R, G, B)
If str = "SP" Then ctl.ForeColor = RGB(250, 0, 0) '' The colour in this case is red text on white
End If
End If
Next
End With
End Sub