next and previous

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

Hello
In a form I have a Previous and a Next button. Like the default navigation
control, next takes you to the next record until you reach the last one and
then it'll go to a new/blank record, and if you click next you get a message
saying you "can't go to the specified record".
What I would like is for the next to stop at the last record, not to go to a
new one and give a message saying "No more records"
Is this possible?
Thank you
 
Use something like this in the Current event of your form.

Private Sub Form_Current()

Dim intCount As Integer

With Me.RecordsetClone
.MoveLast
intCount = .RecordCount
End With

Me.cmdPrevious.Enabled = Me.CurrentRecord <> 1 And Not Me.NewRecord
Me.cmdNext.Enabled = Me.CurrentRecord <> intCount And Not Me.NewRecord

End Sub
 
Thank you that is perfect.
Can you please tell me how to make it apply to my Next and Previous cmd
buttons coz it worked with the forms default navigation controls but I will
be hiding those.
Thank you
 
You just need to modify these lines-

Me.cmdPrevious.Enabled =
Me.cmdNext.Enabled =

to reflect the actual names of your cammand buttons. So it would be;

Me.NameOfYourPreviousButton.Enabled =
Me.NameOfYourNextButton.Enabled =
 
Back
Top