Share via

Access 2013 Runtime error 2105 acPrevious

Anonymous
2015-12-28T09:25:51+00:00

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

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2015-12-28T09:50:55+00:00

    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.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2015-12-28T17:56:52+00:00

    Thank you all for your feedback, really helpful.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-12-28T12:55:45+00:00

    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

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-12-28T09:37:49+00:00

    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

    Was this answer helpful?

    0 comments No comments