What's wrong with this code? Any ideas?

L

Lee

Hi everyone,
Can you tell me what I should do to stop a runtime error
when the procedure gets to the end of file (EOF) - I get
error 3021 "No current record". Here's the code:

varCentre = txtCentre
intCounter = 0

With Forms!Main.Sub.Form.RecordsetClone
.FindFirst "CentreNo=" & varCentre
If .NoMatch Then
MsgBox "blah, blah..."
End If

Forms!Main.Sub.Form.Bookmark = .Bookmark

If Not .EOF Then
Do While intCounter < 6
intCounter = intCounter + 1
If Not .EOF Then
.MoveNext
'STOPS HERE > Forms!Main.Sub.Form.Bookmark = .Bookmark
ElseIf .EOF Then
.MovePrevious
Forms!Main.Sub.Form.Bookmark = .Bookmark
Exit Do
End If
Loop
End If
End With

Any help would be greatly appreciated!

Many thanks,

Lee
 
D

Dan Artuso

Hi,
You have to check for EOF *AFTER* you movenext, not before.

..MoveNext
If Not .EOF Then
......
 

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