You can do this very efficiently with Conditional Formatting. No code
needed.
1. Open your report in design view.
2. Select all the controls in the detail section, and set their Back Style
property to Transparent.
3. Add a text box to the detail section, and give it these properties:
Control Source =1
Running Sum Over Group
Format: General Number
Visible: No
Name: txtKt
4. Add another text box to the detail section.
Drag it so it covers the whole section.
From the Format menu, choose Send to Back.
From the Format menu, choose Conditional Formatting
5. Set Condition 1 of the Condtional Formatting to:
Expression Is ((([txtKt]-1)\3) Mod 2)=1
and click they gray you want in the Fill icon (bucket).
How it works:
- txtKt acts as a counter, incrementing by 1 each row;
- subtracting 1 results in counting 0, 1, 2, 3, 4, 5, 6, 7, ...
- integer division by 3 results in 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, ...
- Mod 2 yields 0 for even numbers, and 1 for odd numbers.
- The gray color is applied to even numbers.