Let's loose all the stupid loops.
Oh please tell me you "Dim LastTopCat" at the top of the page right?
Try this:
If Not RS.EOF Then
Response.Write("<table width=""570"" border=""1"">")
TopCat = RS("topcategory")
MiddleCat = RS("middlecategory")
LastTopCat = ""
i = 3
Do While Not RS.EOF
If i = 3 Then
Response.Write("<tr>")
i = 0
End If
If TopCat <> LastTopCat Then
Response.Write ("<td width=""190"">")
Response.Write(TopCat & "<br />")
Response.Write("-----------------------------")
LastTopCat = TopCat
End If
If TopCat = LastTopCat Then
Response.Write(MiddleCat)
End If
RS.MoveNext
If TopCat <> RS("topcategory") Then
TopCat = RS("topcategory")
End If
MiddleCat = RS("middlecategory")
If TopCat <> LastTopCat Then
Resposne.Write("</td>")
i = i + 1
End If
If i = 3 Then
Response.Write("</tr>")
End If
Loop
Response.Write("</table>")
End If