Skip to content Skip to sidebar Skip to footer

Alternating Colors Of Rows With HTML

I am currently writing code in VBA to automate a process that sends out an e-mail that contains a table with information generated by a query in an Access database. I am using HTML

Solution 1:

Create a counter variable before you go into your loop that will let you keep track of your row number, like this:

i = 1
Do Until rst.EOF
    If i Mod 2 = 0 Then
        Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ffffff'>"
    Else
        Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ccffcc'>"
    End If
    Bodytext2 = Bodytext2 & _
    "<TD> " & rst![Field1] & _
    "<TD> " & rst![Field2] & _
    "<TD> " & rst![Field3]
    rst.MoveNext
    i = i + 1
Loop

My apologies for any syntax errors. My VBA is a little rusty.


Post a Comment for "Alternating Colors Of Rows With HTML"