Access Form - Next and Previous Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to limit the movement beyond the end of a recordset in a filtered
form (not a DAO recordset) using "Next" and "Previous" buttons, and am having
problems determining the CurrentRecord.
 
I am trying to limit the movement beyond the end of a recordset in a filtered
form (not a DAO recordset) using "Next" and "Previous" buttons, and am having
problems determining the CurrentRecord.

Code the Form's Current event:

CmdPreviousRecord.Enabled = Not Me.CurrentRecord = 1

CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or
Me.CurrentRecord < Me.Recordset.RecordCount

The CmdNextRecord code should be all on one line.
 
Here is a procedure I have in a standard module that I use for all my forms.
You just have to be consistent about the names of the buttons.

Sub SetNavButtons(ByRef frmSomeForm As Form)

On Error GoTo SetNavButtons_Error

With frmSomeForm
If .CurrentRecord = 1 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = .Recordset.RecordCount Then
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdPreviousRec.SetFocus
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
Else
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
End If
End With
 
Thanks or your help. That code gets me really close.

I actually have a form where the user enters search criteria, I build that
search criteria into a SQL statement that I use when I open the form in
question.

I'm still having a couple of problems with the form. The Next and Previous
buttons are working fine, but I have an unbound text box I'm using to display
"Record 1 of 5" type information. When the selection criteria returns
multiple records, the number of records returned is 1 until I hit the Next
button the first time, then the correct number is displayed. When the
selection criteria returns only one record, in some cases the number of
records comes back as 2 (instead of 1) and my navigation buttons are disabled.

Any ideas?
 
Back
Top