Error handler help

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
 
D

Douglas J. Steele

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
 
D

Dorian

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".
 
S

SoggyCashew

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
 
D

Douglas J. Steele

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
 

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