next and previous

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
 
B

Beetle

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
 
J

JB

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
 
B

Beetle

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 =
 
L

Linq Adams via AccessMonster.com

Here's two simple routines with messageboxes:

Private Sub Next_Click()
If CurrentRecord = RecordsetClone.RecordCount Then
MsgBox "You are on the Last Record!"
Else
DoCmd.GoToRecord , , acNext
End If
End Sub

Private Sub Previous_Click()
If CurrentRecord = 1 Then
MsgBox "You are on the First Record!"
Else
DoCmd.GoToRecord , , acPrevious
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top