No current record error 3021

G

Guest

I have produced the following code that runs perfectly, but gives me the No
current record error 3021. It is designed to loop through a sorted recordset
and write an "I" for the first occurance of a bandnum and an "R" for all
subsequent occurrances. Is there anything I can do to avoid this error?

Sub CaptureType()
Dim db As DAO.Database
Dim rst1 As Recordset
Dim CurrentID As String
Dim sSQL As String
Set db = CurrentDb()
Set rst1 = db.OpenRecordset("Exercise", dbOpenDynaset)
rst1.Sort = "[BANDNUM],[EvDate]"
Set rst1 = rst1.OpenRecordset
rst1.MoveFirst

Do Until rst1.EOF

CurrentID = rst1!BANDNUM
sSQL = "[BANDNUM] = '" & CurrentID & "'"
rst1.FindFirst sSQL
rst1.Edit
rst1!Capture = "I"
rst1.Update
rst1.MoveNext

Do While rst1!BANDNUM = CurrentID
rst1.Edit
rst1!Capture = "R"
rst1.Update
rst1.MoveNext
Loop
Loop

rst1.Close
Set rst1 = Nothing
Set db = Nothing

End Sub
 

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

Similar Threads


Top