Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2014
    Posts
    22
    Provided Answers: 1

    Unanswered: Keep form from showing new/blank record at end of records when clicking next record

    I have a form showing all records. When you go to the last record. I have created Next/Previous/Last/First buttons instead of Access navigation. When the user goes to the last record and clicks next record, I want a message box telling them they are on the last record. Also do it with first record Previous button getting clicked.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I use code to 'wrap' around to the opposite end of the recordset. If you get to the end of the Recordset, hitting Next or Previous 'wraps' it to the First Record or the Last Record, respectively.

    Code:
    Private Sub Go2Prev_Click()
    
      If Me.CurrentRecord = 1 Or Me.NewRecord = True Then
    
        DoCmd.GoToRecord , , acLast
    
      Else
      
        DoCmd.GoToRecord , , acPrevious
    
      End If
    
    End Sub


    Code:
    Private Sub Go2Next_Click()
    
      If Me.CurrentRecord = Me.RecordsetClone.RecordCount Or Me.NewRecord = True Then
     
        DoCmd.GoToRecord , , acFirst
    
      Else
    
        DoCmd.GoToRecord , , acNext
    
      End If
    
    End Sub

    If you don't want this behavior, you can use the same tests and to do nothing if on the First Record or Last Record, or pop a Messagebox telling the user the situation and then do nothing.

    Code:
    Private Sub Go2Prev_Click()
    
    
      If Me.CurrentRecord = 1 Or Me.NewRecord = True Then
    
        MsgBox "You are on the First Record!"
    
      Else
      
        DoCmd.GoToRecord , , acPrevious
    
      End If
    
    End Sub

    Code:
    Private Sub Go2Next_Click()
    
      If Me.CurrentRecord = Me.RecordsetClone.RecordCount Or Me.NewRecord = True Then
     
        MsgBox "You are on the Last Record!"
    
      Else
    
        DoCmd.GoToRecord , , acNext
    
      End If
    
    End Sub


    Linq ;0)>
    Last edited by Missinglinq; 12-02-14 at 13:03.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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