Next record button on a form (1 Viewer)

crowegreg

Registered User.
Local time
Today, 10:11
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.
 

Catalina

Registered User.
Local time
Today, 09:11
Joined
Feb 9, 2005
Messages
462
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
 

crowegreg

Registered User.
Local time
Today, 10:11
Joined
Feb 28, 2011
Messages
108
I'll add your suggestion. Thanks for providing the complete code!!
 

missinglinq

AWF VIP
Local time
Today, 12:11
Joined
Jun 20, 2003
Messages
6,423
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

Top Bottom