Consulting

Results 1 to 2 of 2

Thread: [ HELP ] Run Time Error 2105

  1. #1

    [ HELP ] Run Time Error 2105

    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.

    c002.JPG

    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.

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •