GoToRecord error 2105

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I can't seem to trap this error!

I have a command button to take you to the next record. If there is not a
"next record" I'd like a message box stating "you've reached the end of the
list", instead of the dreaded "run-time error 2105 you can't go to the
specified record".

When I step through my code, the error doesn't seem to get pegged as 2105
and the message box doesn't appear. I must have something backwards! I'd
appreciate your help. Thanks!

Private Sub NextPP_Click()
Dim lngErr As Long

lngErr = Err.Number
If (lngErr <> 0) And (lngErr = 2105) Then
MsgBox "That's the last entry in the list.", _
vbInformation, "End of the list..."
Else
DoCmd.GoToRecord , , acNext

End If

On Error GoTo ProcError

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in NextPP_Click procedure..."
Resume ExitProc

End Sub
 
It's your

DoCmd.GoToRecord , , acNext

statement that raises the error. Check Err.Number before you execute that
statement won't help in any way.

Try:

Private Sub NextPP_Click()
On Error GoTo ProcError

DoCmd.GoToRecord , , acNext

ExitProc:
Exit Sub

ProcError:
Select Case Err.Number
Case 2105
MsgBox "That's the last entry in the list.", _
vbInformation, "End of the list..."
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in NextPP_Click procedure..."
End Select
Resume ExitProc

End Sub
 
Thanks for the post and the lesson!

Douglas J. Steele said:
It's your

DoCmd.GoToRecord , , acNext

statement that raises the error. Check Err.Number before you execute that
statement won't help in any way.

Try:

Private Sub NextPP_Click()
On Error GoTo ProcError

DoCmd.GoToRecord , , acNext

ExitProc:
Exit Sub

ProcError:
Select Case Err.Number
Case 2105
MsgBox "That's the last entry in the list.", _
vbInformation, "End of the list..."
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in NextPP_Click procedure..."
End Select
Resume ExitProc

End Sub
 
Back
Top