I managed to fix it. Basically, I only have two forloops, one to add controls to one table, and other to add controls to the remaining two tables. I separated this second loop in two, for each table, and now it works.