MsgBox Err.description

G

Guest

I have the following code attached to a form navigation button (nextRecord).
How do I change it so it displays a custom error message? When a user clicks
on the "Next Record" button, and there are no more records, instead of
getting the standard "You can't go to the specified record" error message, I
want it to say "There are no more records for this employee." I know I need
to make the change in the last 5 lines of code, but I'm having trouble with
the syntax.

Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click

DoCmd.GoToRecord , , acNext

Exit_Next_Record_Click:
Exit Sub

Err_Next_Record_Click:
MsgBox Err.description
Resume Exit_Next_Record_Click

End Sub
 
B

bob

try this:

If Err.Number = 94 Then
MsgBox "There are no more records for this employee."
Else
End If

Bob Galway
 
G

Guest

Nope, that doesn't work. I was really hoping to do something like this, but
the syntax seems to be wrong since it doesn't work:

Err_previousRecord_Click:
MsgBox "There are no more records for this employee."
Resume Exit_previousRecord_Click

Thanks for taking time to reply!

GwenH
 
R

RD

Well, you skipped the "If" part! Bob's suggestion should work perfectly if you
implement it correctly.

Err_previousRecord_Click:
If Err.Number = 94 Then
MsgBox "There are no more records for this employee."
Resume Exit_Next_Record_Click
Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Next_Record_Click
End If
 
G

Guest

I copied Bob's code and pasted it into mine, so I know I implemented it
correctly. It didn't matter if I used it on the "nextRecord" or
"previousRecord" button - when I reached the first or last record, no error
messages at all displayed.

I'm using Access 2003, if that makes any difference.
 
R

RD

This is what Bob posted:
If Err.Number = 94 Then
MsgBox "There are no more records for this employee."
Else
End If

This is what I posted:
Err_previousRecord_Click:
If Err.Number = 94 Then
MsgBox "There are no more records for this employee."
Resume Exit_Next_Record_Click
Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Next_Record_Click
End If

And this is what you posted:
Err_previousRecord_Click:
MsgBox "There are no more records for this employee."
Resume Exit_previousRecord_Click


I don't know that 94 is the actual error number you're getting. You will have
to step through your code to determine that. The code snippets that Bob and I
posted work.
 

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