Take a look at
this[
^] thread where someone had the same error.
Note particularly the
while
loop and the couple of lines before it. (the
beforefirst()
call)
From this I have gathered that the cursor gets positioned past the end of the result set when the query is executed.