Runtime Error 3021: 'No Current Record'

M

Manuel

I don't understand why I'm getting runtime error 3021: 'No Current Record'
when I run the below code. There are 8 records in the table and on the last
record, after MoveNext, I get the error. But why, since I'm on a current
record. Here's the code:

Function CreateExceptionTable()

Dim strSQL As String
Dim db As dao.Database
Dim rst As dao.Recordset
Dim i As Integer

Set db = CurrentDb
Set rst = db.OpenRecordset("tblSLQStmts")

DoCmd.SetWarnings False

rst.MoveFirst
i = rst.RecordCount

strSQL = rst("ExceptionCkSQL").Value

Do While i > 0

db.Execute strSQL

If Not rst.EOF Then
rst.MoveNext
strSQL = rst("ExceptionCkSQL").Value 'HERE IS WHERE I GET THE
ERROR!
End If

i = i - 1

Loop

DoCmd.SetWarnings True

End Function

Any help would be appreciated.

Thanks,
Manuel
 
J

John Spencer

Try moving the rst.MoveNext after the strSQL = rst("ExceptionCkSQL").Value


Or better yet change the loop

While Not rst.Eof
'Do stuff
strSQL = rst("ExceptionCkSQL")
db.Execute strSQL
rst.Move Next
Wend


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
D

DaveT

....
if rst.eof then
'no records to begin with so close and exit
end if


rst.movelast
i = rst.recordcount
rst.movefirst

'no need to use recordcount and For ... Next construction

Do

strSQL = ....
db.execute strSQL
rst.movenext

loop while not rst.eof

<>

I would say your code gets No Current Record because you have rst.movenext
before you set strSQL = something

movenext will eventually get you to the end of the recordset and throw 3021.
So check for EOF before you try to make assignments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top