How to tell when on last record (programmatically)

B

Brian

I have an app that runs unattended with this on the form timer:

DoCmd.GoToRecord acDataForm, Me.Name, acFirst
'Do stuff here
Do While ?? (this is the question - do while not on last record)
DoCmd.GoToRecord acDataForm, Me.Name, acNext
Loop

Now, I know how to use a recordset and "Not EOF" to find out when I am at
the end of a recordset. How can I determine if I am on the last record when
simply running through the records on the form, though? (yes, I know that I
could just look for a null required field or something like that, but I'm
trying to simply prevent navigation past the last record.)

This is probably way too simple, but I'm missing the answer somewhere.
 
M

Marshall Barton

Brian said:
I have an app that runs unattended with this on the form timer:

DoCmd.GoToRecord acDataForm, Me.Name, acFirst
'Do stuff here
Do While ?? (this is the question - do while not on last record)
DoCmd.GoToRecord acDataForm, Me.Name, acNext
Loop

Now, I know how to use a recordset and "Not EOF" to find out when I am at
the end of a recordset. How can I determine if I am on the last record when
simply running through the records on the form, though? (yes, I know that I
could just look for a null required field or something like that, but I'm
trying to simply prevent navigation past the last record.)


You may be able to just check Me.NewRecord to see if you
went past the last record.

A more complete way is to move through the form's
RecordsetClone and use a bookmark to navigate the form's
records.

With Me.RecordsetClone
.MoveFirst
Do Until .EOF
Me.Bookmark = .Bookmark
''Do stuff here
.MoveNext
Loop
End With
 
B

Brian

Thank you. Me.NewRecord does it. I use that ALL the time for other things,
but you just spared me from a case of tunnel vision...
 

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