DoCmd.GoToRecord

G

Guest

Hi, I created a command button to move to the next register in my form, how
can I do to control the messages when the end of the file is reached, because
now says something like "You Can't go to the selected register" I would like
to change that message for something more specific.

If someone have an Idea of How to do that, I would appreciated.


Private Sub Command28_Click()
On Error GoTo Err_Command28_Click


DoCmd.GoToRecord , , acNext

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub
 
K

Ken Snell \(MVP\)

Try this (I also changed your code so that it uses MoveNext action of
Recordset object instead of the DoCmd approach):
---

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click

If Me.Recordset.EOF = False Then
Me.Recordset.MoveNext
Else
MsgBox "You're already on the last record."
End If

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub
 
G

Guest

You can use the error capture to check the error number and give a different
message

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click


DoCmd.GoToRecord , , acNext

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
If Err = 2105 Then
MsgBox "You reached the last record"
Else
MsgBox Err.Description
End If
Resume Exit_Command28_Click

End Sub
 
G

Guest

Thanks Guys, It works perfect.


Ken Snell (MVP) said:
Try this (I also changed your code so that it uses MoveNext action of
Recordset object instead of the DoCmd approach):
---

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click

If Me.Recordset.EOF = False Then
Me.Recordset.MoveNext
Else
MsgBox "You're already on the last record."
End If

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

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