Access 2013 Runtime error 2105 acPrevious

I am getting this runtime error 2105 when cycling through my records, if I hit previous when on record 1 I get the error.

Here is my code:

Private Sub Command25_Click()

'go to previous record
DoCmd.GoToRecord , , acPrevious

 

End Sub

 

Question Info


Last updated December 20, 2017 Views 593 Applies to:

ciao Stefen,

if you are on the first record and you are trying to move back again :

Private Sub cmdMovePrevious_Click()
If Me.CurrentRecord = 1 Then Exit Sub
DoCmd.GoToRecord acDataForm, Me.Name, acPrevious
End Sub

if you are on the last record and you are trying to move ahead again :

Private Sub cmdMoveNext_Click()
If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then Exit Sub
DoCmd.GoToRecord acDataForm, Me.Name, acNext
End Sub

of course, you could also advise your user with a msgbox notifying you are on the first or on the last records and you cannot move back or ahead....

Moreover, I would recommend to rename the controls in your with more significant names....Command25 cannot allow you to understand what it stands for...

ciao, Sandro.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Hi,

you can handle the error so as:

Private Sub cmdNew_Click()
on error got MyErr
    DoCmd.GoToRecord acActiveDataObject, , acNewRec
    Call CarryOver(Me)
MyExit:
  exit sub
MyErr:
  if err.number<>2105 then
    msgbox err.description
  end if
  resume MyExit
End Sub

Mimmo

Se la risposta ti ha aiutato "Vota Utile".
Se ha risolto il problema "Segna Risposta.
Rome, Italy

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

The reason for the error is you are trying to go to a record that doesn't exist. It appears you have tried to create your own "VCR" buttons to navigate through records. The problem with this is you make no provision for when you have reached the first or last record. So you need to do some trapping here. One way would be to trap and then ignore the error or maybe add a:

MsgBox "You are on the first record!"

in your error trapping. Another way is to check to see if you are on the first or last record before executing the GotoRecord (BTW, you should use DoCmd.RunCommand instead of the older GotoRecord).

Your previous answers gave examples of these. Without knowing how much code you are using its harder to advise. Here is another example:

https://bytes.com/topic/access/answers/751676-custom-record-navigation-buttons

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Thank you all for your feedback, really helpful. 

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.