The attached demo does the same: it iterates through an Access-based dataset and counts the empty fields, and the error does not occur.
What is different to your case? I could imagine that the fact that the query is attached to a DBGrid in my demo could cause .Last already being called. So, please give more details, or better: upload a simple compilable demo (only pas, lfm, lpi, lpr and database files, all in a common zip, like I did).