Actually, When I cut and pasted in my example, I forgot a line from my original code… after the If statement.
$currbackcolor = $newbackcolor;
and it still didn’t work. (Actually it worked once on the first and second record.) Thats why I thought it was something specific to the foreach statement.