How to stop 2105 Message, Can't go to next record (Urgent, please help!)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steed
    New Member
    • Feb 2008
    • 3

    How to stop 2105 Message, Can't go to next record (Urgent, please help!)

    Hey all, this is hopefully so simple you want to laugh me off the forum but it would Really Really help if you could...well help me!

    I've got this 'browse' form to allow user to go through records one by one, but when I get to the end of the data two things happen:

    First, it goes to a blank page (to make a new record I assume) - This is fine.

    One more click after that I get a "2105" Which states "You can't go to specified record". however when it does this its an ugly box with 'end debug help' - This I do not want!

    How do I add my own message just saying 'no more records'?

    Thank you kindly!

    oh btw the code for the button is:

    Private Sub btn_Next_Rec_Cl ick()
    DoCmd.GoToRecor d , , acNext
    End Sub
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Originally posted by Steed
    Hey all, this is hopefully so simple you want to laugh me off the forum but it would Really Really help if you could...well help me!

    I've got this 'browse' form to allow user to go through records one by one, but when I get to the end of the data two things happen:

    First, it goes to a blank page (to make a new record I assume) - This is fine.

    One more click after that I get a "2105" Which states "You can't go to specified record". however when it does this its an ugly box with 'end debug help' - This I do not want!

    How do I add my own message just saying 'no more records'?

    Thank you kindly!

    oh btw the code for the button is:

    Private Sub btn_Next_Rec_Cl ick()
    DoCmd.GoToRecor d , , acNext
    End Sub
    You can test or the last record (you allow "new") is the new record and skip the action like:
    [code=vb]
    Private Sub btn_Next_Rec_Cl ick()
    If Me.Newrecord then
    ' no action
    else
    DoCmd.GoToRecor d , , acNext
    end if
    End Sub
    [/code]

    Personally I prefer to disable such a [Next] button on forhand by adding to the OnCurrent event of the form. As you'll also want to protect the btnPrevious, you could use code like:
    [code=vb]
    Private Sub btnFirst_Click( )

    DoCmd.GoToRecor d , , acFirst
    Call subEnable

    End Sub
    Private Sub btnPrev_Click()

    DoCmd.GoToRecor d , , acPrevious
    Call subEnable

    End Sub
    Private Sub btnLast_Click()

    DoCmd.GoToRecor d , , acLast
    Call subEnable

    End Sub
    Private Sub btnNext_Click()

    DoCmd.GoToRecor d , , acNext
    Call subEnable

    End Sub

    Sub subEnable()

    ' init buttons
    Me.btnFirst.Ena bled = True
    Me.btnPrev.Enab led = True
    Me.btnLast.Enab led = True
    Me.btnNext.Enab led = True

    ' correct for first and last row reached
    If Me.CurrentRecor d = 1 Then
    Me.btnNext.SetF ocus
    Me.btnFirst.Ena bled = False
    Me.btnPrev.Enab led = False
    End If

    If Me.CurrentRecor d = Me.Recordset.Re cordCount Then
    Me.btnPrev.SetF ocus
    Me.btnLast.Enab led = True
    Me.btnNext.Enab led = False
    End If


    End Sub

    Private Sub btnTagTest_Clic k()
    Dim ctl As Control

    For Each ctl In Me.Controls
    If ctl.Tag <> "" Then
    Debug.Print ctl.Name, ctl.Tag
    End If
    Next
    End Sub
    [/code]

    BTW, the above code doesn't allow new records, check the difference :-)

    Getting the idea ?

    Nic;o)

    Comment

    Working...