Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eof trapping on GoToRecord,,acNext 2

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hello everybody,
I try to trap EOF on a GoToNextRecord-action on a filtered form. I tried this, but no good:

Code:
If Not rs.EOF Then
    DoCmd.GoToRecord , , acNext
    Else
        MsgBox "you reached the last record for this voyage"
    End If

Pampers [afro]
There is only one way to change a diaper - fast
 
How are ya pampers . . .

. . . and this:
Code:
[blue]   If Me.CurrentRecord <> Recordset.RecordCount Then
      DoCmd.RunCommand acCmdRecordsGoToNext
   Else
      MsgBox "you reached the last record for this voyage"
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
You could use the error handler of the sub to post the message. My example uses a sub called Go2Next_Click to advance to the next record. You could, of course substitute the name of your sub.


Private Sub Go2Next_Click()

On Error GoTo Err_Go2Next_Click
DoCmd.GoToRecord , , acNext

Exit_Go2Next_Click:
Exit Sub

Err_Go2Next_Click:
MsgBox "you reached the last record for this voyage"
End Sub

Or you could do as I do and have the app "wrap around" back to the first record after the last record is reached:

Private Sub Go2Next_Click()

On Error GoTo Err_Go2Next_Click
DoCmd.GoToRecord , , acNext

Exit_Go2Next_Click:
Exit Sub

Err_Go2Next_Click:
DoCmd.GoToRecord , , acFirst
End Sub

Likewise, you can have your "Previous" button wrap around to the last record:

Private Sub Go2Prev_Click()

On Error GoTo Err_Go2Prev_Click
DoCmd.GoToRecord , , acPrevious

Exit_Go2Prev_Click:
Exit Sub

Err_Go2Prev_Click:
DoCmd.GoToRecord , , acLast
End Sub

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
Thanks a lot guys for the response.
Tried both, TheAcemans code didn't do it for me. Missinglinq's works smooth... I use the non-'wrap around' because this time it shouldn't proceed to the first record again... but the 'wrap around' is very nice.

Pampers [afro]
There is only one way to change a diaper - fast
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top