you can't go to the specified record error

suepowell

Registered User.
Local time
Today, 00:15
Joined
Mar 25, 2003
Messages
282
Hi

I'm sure this has been answered several times, but I can't find the right thread to give me the answer.

I have this piece of code in an access 2000 database

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

DoCmd.GoToRecord , , acnextExit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click

End Sub

If I am on the last record I get the error message "you can't go to the specified record."

I would like to trap this error and put out my own msgbox with something more informative, but I am not triggering the error routine in the sub.

I know this beacuse I have tried putting my own message in the msgbox line and I still get the standard one.

How can I stop the standard message and put my own in instead

Thanks

Sue
 
try the following: ... i tested it on a form of mine and it works without getting the standard error message

Code:
On Error GoTo Err_Form_KeyDown
Select Case KeyCode
Case vbKeyDown
DoCmd.GoToRecord , , acNext
KeyCode = 0

Case vbKeyUp
DoCmd.GoToRecord , , acPrevious
KeyCode = 0

Case vbKeyReturn
DoCmd.GoToRecord , , acNext
KeyCode = 0

Case Else

End Select
Exit Sub
Err_Form_KeyDown:
Select Case KeyCode

Case vbKeyDown
MsgBox "No More Records to Display", vbExclamation + vbOKOnly, "Warning ..."

Case vbKeyUp
MsgBox "You are already at the First Record", vbExclamation + vbOKOnly, "Warning ..."

Case vbKeyReturn
MsgBox "No more records to move to", vbExclamation + vbOKOnly, "Warning ..."
Case Else

End Select

Note that you may need to amend your code to suit your needs!
 
Hi
Thanks for the reply.

I am not sure where the keycode comes from, I have 1 button for next record and one button for previous record so I don't think this is relavent.
I am already using an on error line to send the code to an error handling routine.

On my system the docmd.gotorecord event does not trigger the error handling, so I can't put my own message in, the standard message is not coming from the error routine at the end of the sub, so i can't get into it to change it.

I am using access xp with the database in access 2000 format.

has anybody any other ideas?

Thanks

Sue
 
Thanks, that was what I needed.

I used the disabling code and it seems to work well.

Pity we can't just use on error though, it would be easier!

Thanks again

Sue
 
suepowell said:
Thanks, that was what I needed.

I used the disabling code and it seems to work well.

Pity we can't just use on error though, it would be easier!

Thanks again

Sue
you can by using the Forms error event
 
Hi Rich

That sounds intreiging, how would I do it.

I tried putting a message box in the forms on error event to see if I got there, but just the same message as before, so I must be doing something wrong

Sue
 
In the form error, you have to return a response.

i.e.

Response = acDataErrContinue

Response = acDataErrAdded
 
I think you have to trap the actual error number
something like
If DataErr = 3201 Then
'Display Error Message
MsgBox "Your message"
'Prevent the standard error message from showing
Response = acDataErrContinue
Else
'If another error is applied then show the standard error message
Response = acDataErrDisplay
End If

you'll have to look up the error number to trap it
 
Thanks Mile-0-Phile and Rich,

I have got the button disabling software to work now, so I'll press on with the project for my customer.

This could be useful stuff to know, so I've saved it away for when i've got a bit more time.

Thanks again

Sue.
 

Users who are viewing this thread

Back
Top Bottom