Error handler help

  • Thread starter Thread starter SoggyCashew
  • Start date Start date
S

SoggyCashew

Hello, I have a buttin on my form that takes me to the precious record. If I
go back to far it gives me a 2105 error. I Wanted to have a custom mesage and
an ok button but I cant get it to work. It still opens the error window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number <> 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
 
Err_MyErr:
If Err.Number <> 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
Msgbox "Oops: you can't go any further!"
Resume Next
End If

End Sub
 
You should disable the PREV button when at the top, and the NEXT button when
at the bottom, so this can never occur.
There are standard techniques for doing this, google them.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
Douglas, Im getting an error: label not defined? Also, Dorianthak I hae tried
to google your answer to my question but with no luck.

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Err_MyErr:
If Err.Number <> 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
MsgBox "Oops: you can't go any further!"
Resume Next
End If

End Sub
 
You forgot to include

Exit_MyErr:
Exit Sub

The entire thing should be

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious


Exit_MyErr:
Exit Sub

Err_MyErr:
If Err.Number <> 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
MsgBox "Oops: you can't go any further!"
Resume Next
End If

End Sub
 
Back
Top