When I use Continuous Forms in an MSAccess Form, it automatically applies an Alternate Row Color to every other row.
I would like to have the alternate row color for groups of rows of data.
Some groups might have just one row, but others will have more than one.
I do have a column in the form with an integer that increments for each group.

Is there a way to get Access to recognize the Grouping in the Form and then apply Alternate Row Color there rather than simply every other row?


Access does not have a way to recognize Grouping in Forms in the UI. (it does in Reports)

However, there is an Event of the Detail Section that provides an appropriate hook for formatting, even without the UI "Grouping".

enter image description here

Since there is an integer index for the groups, and we want to alternate by group, it is easy to just check for even/odd groups and set the background colors.
We need to force both "Backcolor" and "AlternateBackColor". So assuming the group index is put in a textbox named IndexColumnBox, it can be as...

Private Sub Detail_Paint()

    If Me.IndexColumnBox.Value Mod 2 = 0 Then
        Detail.BackColor = &HDDDDDD
        Detail.AlternateBackColor = &HDDDDDD

        Detail.BackColor = &HFFFFFF
        Detail.AlternateBackColor = &HFFFFFF

    End If

End Sub

(Note the event is screen paint, and not just generating the Continuous Forms once. So this event will be called any number of times for each row as the Form is scrolled and used. This means it is key to have something like the index column check that is always the same.)

  • If anyone can find a better event than Detail_Paint it can be interesting. It does cause side effects when the groupings change, such as in my case where this is a subform and I change records in the parent. – Mike M Oct 29 '17 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.