PDA

View Full Version : [SOLVED:] Run Time Error 2105



mcSpringy
08-04-2016, 04:01 AM
Hi All,

I've made a bare basic Access db. I have also added some records navigation buttons for it. The thing is, when if I am on the very first record or the last record, and I press previous or next buttons, I get the Run Time Error 2105.

16787

Is there a code that I could use so that when I press next or previous on the last and first entries that Access would show no further records exists.

--- or ---

Is there an IF or other code that when that I press the next button on the last record, it loops back to the first record and vice versa.

Here's my next and previous button codes.


Private Sub cmdNewRecord_Click()
DoCmd.GoToRecord , , acNewRec
End Sub

Private Sub cmdNextRecord_Click()
DoCmd.GoToRecord , , acNext
End Sub

Private Sub cmdPreviousRecord_Click()
DoCmd.GoToRecord , , acPrevious
End Sub


P.S. I'm really rusty with vba, basic codes would be of big help.

jonh
08-04-2016, 04:50 AM
Use error handling.


Private Sub cmdPreviousRecord_Click()
MvToRec Me, acPrevious
End Sub


Private Sub cmdNextRecord_Click()
MvToRec Me, acNext
End Sub


Sub MvToRec(frm As Form, mv As Access.AcRecord)
On Error Resume Next
DoCmd.GoToRecord , frm.Name, mv
Select Case Err.Number
Case 0 'no error
Case 2105
'if first record reached jump to last and vice versa
Select Case mv
Case acNext: mv = acFirst
Case acPrevious: mv = acLast
End Select
MvToRec frm, mv
Case Else
Debug.Print Err.Number, Err.Description
End Select
End Sub