I've experienced this problem a few times.
Typically it happens to me when I have hidden textbox executing some Code.xxx routine and that textbox is located under a table and the table has some kind of group page break.
It seems that with each page break, the fields hidden under the table are refreshed and sometimes get a object reference error.
Here's the weird thing.
I can typically fix the problem simply by moving all the hidden fields to a location such that their upper left corner is above the table's upper left corner, or to the left of it. It's like the position of the field somehow has smoe influence on what is refreshed and what is not.
I do not claim to know why it works, it just does.