PDA

View Full Version : Record stepping controls - detecting last record



PThomas
07-25-2007, 08:02 AM
As part of my on-screen controls I have a next and previous record button. How can I stop the user from being able to go to the last record and then choosing next to create a new one?

My code for next:-

Private Sub Btn_NextCall_Click()
On Error GoTo Err_Btn_NextCall_Click
DoCmd.GoToRecord , , acNext
Forms![frm_Hotline_Call]![CustomerName].Requery
Forms![frm_Hotline_Call]![CustomerSite].Requery
Forms![frm_Hotline_Call]![CustomerSiteContact].Requery
Forms![frm_Hotline_Call]![Equipment].Requery
Forms![frm_Hotline_Call]![EquipmentType].Requery
Exit_Btn_NextCall_Click:
Exit Sub
Err_Btn_NextCall_Click:
MsgBox Err.Description
Resume Exit_Btn_NextCall_Click

End Sub

Thanks

Paul

OBP
07-25-2007, 09:28 AM
Paul, this code goes in to the Form's "On Current" Event Procedure, it checks that when using Next and Previous Command Buttons that you can't try to go past either the first or last record by disabling the Buttons, the 3rd button in this group is a "New Record" button.
You will have to change it to suit your Button Numbers or names.
Dim rs As Object

Set rs = Me.Recordset.Clone

If rs.RecordCount = 0 Then
Command65.Enabled = True
Command64.Enabled = False
Command66.Enabled = False
End If
rs.Bookmark = Me.Bookmark
rs.MovePrevious
Command66.Enabled = Not (rs.BOF)
rs.MoveNext

rs.MoveNext
Command65.Enabled = Not (rs.EOF)
rs.MovePrevious

rs.Close

PThomas
07-26-2007, 06:37 AM
Thanks

I'll give it a go!

PThomas
07-27-2007, 12:07 AM
OBP

You're a star!

Works very well.

Thanks

Paul

Cosmos75
07-30-2007, 12:41 PM
A little late to the game but I have an example that might be helpful here:
- Form Navigation Buttons (Enabling/Disabling) & Displaying Record X of Y (http://www.accessdb.info/content/view/41/42/)