Next record button on a form

crowegreg

Registered User.
Local time
Today, 15:54
Joined
Feb 28, 2011
Messages
108
Hello, I have a command button on a form to go to the next record. If the current record is the EOF, the command will create a new record. What's the easiest way to display a message that their are no more records, and prevent a new record from being created.
 
I always do it like this:

Code:
Private Sub cmdLastRecord_Click()
    On Error GoTo Err_cmdLastRecord_Click

    Me.AllowAdditions = False
    DoCmd.GoToRecord , , acLast

Exit_cmdLastRecord_Click:
    Exit Sub

Err_cmdLastRecord_Click:
    MsgBox " There are no more records ", vbExclamation, ""
    Resume Exit_cmdLastRecord_Click
    
End Sub

Me.AllowAdditions = False prevents a placeholder for a new record to show.

Make sure to set it back to: Me.AllowAdditions = True when you want to create a new record.

Catalina
 
I'll add your suggestion. Thanks for providing the complete code!!
 
Catalina's code appears to concern going to the last record, not the next record, which was the OP's concern! I use this, which doesn't allow moving to the next record if at EOF and pops a warning to the user:
Code:
Private Sub Next_Click()
  If CurrentRecord = RecordsetClone.RecordCount Then
    MsgBox "You are on the Last Record!"
  Else
    DoCmd.GoToRecord , , acNext
  End If
End Sub
Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom