How to make the next record button in a form stop at the last record ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sam Zuhbi
    New Member
    • Sep 2010
    • 10

    How to make the next record button in a form stop at the last record ?

    Hi,

    I was wondering how do I make the next record button on my access 2007 form stop at the last record, I want to make sure that if it does not create a new record if it reaches the last record because I already have all the records locked and an edit button takes care of editing the current record and a New record button is already created. Any help on this one will be appreciated greatly.

    Thank you for your help
    Sam.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    Code:
    if not recordsetname.eof then
       recordsetname.movenext
    else
       msgbox "Sorry, you cannot go past the end of the file"
    endif
    Last edited by jimatqsi; Sep 8 '10, 06:50 PM. Reason: too quick on the keyboard

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I'm afraid I don't think that will work Jim. That said, there is no neat way to work this that I've ever found. I would use the following code which I admit is clumsy :
      Code:
      Call DoCmd.GoToRecord(Record:=acNext)
      If Me.NewRecord Then Call DoCmd.GoToRecord(Record:=acPrevious)

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        If you are really looking for a professional looking Application with Smart/Intelligent Navigation Buttons, you can eliminate Access's Navigation Buttons, and create your own Custom ones that will test for all conditions using the RecordsetClone Property to move the Record Pointer independently of the Form's Recordset. To post the code would be confusing to say the least, so I created a simple demo for you to Download. This demo should provide exactly what you are looking for.
        Attached Files

        Comment

        Working...