The objective is to have a display-only continuous form where each row's background color depends on the value of one or more fields in that row.
Continuous forms don't seem to provide good event handling. I naively expected that OnCurrent would work for this, but it fires only for the first record. After thinking about this it makes sense as there's only one "Current" record at a time for a form.
I then tried making the fields all transparent and hooking the Detail_Paint event, and got almost what I want:
Code:
Private Sub Detail_Paint()
If IsNull(orderDate) Then ' This is a usage row, color it light pink
Me.Section(acDetail).BackColor = RGB(255, 240, 255)
Me.Section(acDetail).AlternateBackColor = RGB(255, 240, 255)
ElseIf Paid Then ' This is a paid purchase row, color it light green
Me.Section(acDetail).BackColor = RGB(240, 255, 250)
Me.Section(acDetail).AlternateBackColor = RGB(240, 255, 250)
Else ' This is an unpaid purchase row, make it light gray
Me.Section(acDetail).BackColor = RGB(240, 240, 240)
Me.Section(acDetail).AlternateBackColor = RGB(240, 240, 240)
End If
End Sub
Gives me this:
It's exactly what I want, but it leaves the unused portion of the continuous form painted in the last color encountered.
Ideally I'd want an event that fires after a continuous form has been populated, so I can reset the section background colors, but that does not seem to exist.
Conditional formatting works only on individual fields and cannot be applied to a section.
Is there a way to accomplish my goal by either:
1) resetting the section background after the continuous form is populated, or
2) a completely different approach
ADDENDUM: It looks like I might be able to do what I want with Conditional Formatting if I don't leave empty space between fields.
However, this means setting up conditional formatting for every field in the UI.
Is there a way to manipulate conditional formatting from VBA? I can't find any methods or properties for this on the Form, Control or individual control objects.