Reputation: 1
I want to display the first three records of an MS Access report in a different background color using VBA code.
I tried coding in detail-events, but then the whole section was displayed in another color.
Upvotes: 0
Views: 97
Reputation: 21379
Try this:
Place a textbox named tbxCnt in Detail section with ControlSource of =1 and RunningSum set to OverAll (can be set not visible). Code options:
Conditional Formatting rule on each textbox Expression is: [tbxCnt]<4
VBA can test for value of tbxCnt to set Detail section backcolor with:
If Me.tbxCnt < 4 Then Me.Detail.Backcolor = vbYellow Else: Me.Detail.Backcolor = vbWhite
or
Me.Detail.Backcolor = IIf(Me.tbxCnt < 4, vbYellow, vbWhite)
Make sure AlternateBackColor is set for NoColor.
Upvotes: 1
Reputation: 1146
This works in print preview:
SUB DETAIL_FORMAT
IF (condition) THEN
DETAIL.BACKCOLOR = ...
ELSE
DETAIL.BACKCOLOR = ...
END IF
END SUB
This works in report view:
SUB DETAIL_PAINT
IF (condition) THEN
DETAIL.BACKCOLOR = ...
ELSE
DETAIL.BACKCOLOR = ...
END IF
END SUB
Upvotes: 1