paulusg62
paulusg62

Reputation: 1

Give a different background color to the first three records of an MS Access report

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

Answers (2)

June7
June7

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:

  1. Conditional Formatting rule on each textbox Expression is: [tbxCnt]<4

  2. 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

Shahram Alemzadeh
Shahram Alemzadeh

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

Related Questions