Moving to Next Record

N

Nad

Hi Genius,
I have a ProjectUpdate form. The record source of this form is a query.
I remove the navigation buttons from the form and i want to create custom
navigation button.
What code requires to move to the next record.

Please help
 
S

Stuart McCall

Nad said:
Hi Genius,
I have a ProjectUpdate form. The record source of this form is a query.
I remove the navigation buttons from the form and i want to create custom
navigation button.
What code requires to move to the next record.

Please help

DoCmd.RunCommand acCmdRecordsGoToNext
 
N

Nad

Thanks Stuart,
But it is giving error when i am in the last record.(RecordsGoToNext isn't
available)
Because it is my Project Update Form so i set the AllowAddition property of
the form to False.
Please guide me.
Regards
 
S

Stuart McCall

Nad said:
Thanks Stuart,
But it is giving error when i am in the last record.(RecordsGoToNext isn't
available)
Because it is my Project Update Form so i set the AllowAddition property
of
the form to False.
Please guide me.

The simplest way to deal with this is to instruct Access to ignore the
error:

On Error Resume Next
DoCmd.RunCommand acCmdRecordsGoToNext
 
L

Linq Adams via AccessMonster.com

So what do you want to happen when you get to the end of your records?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
L

Linq Adams via AccessMonster.com

I use custom nav buttons and only selectively allow additions, and what I do
is simply "wrap" around to the beginnig of the recordset when I get to the
end of it. SInce the only error I've ever encountered in moving from record
to record is the
same as you're getting "Can't go to specified record" I simply use the errro
handler to do the wrapping. I ve never had a problem with it. I also do the
reciprocal thing when at the first record and try to go to a previous record;
wrap arounf to the last record.

Private Sub Go2Next_Click()
On Error GoTo Err_Go2Next_Click
DoCmd.GoToRecord , , acNext
Exit_Go2Next_Click:
Exit Sub

Err_Go2Next_Click:
DoCmd.GoToRecord , , acFirst
End Sub


Private Sub Go2Prev_Click()
On Error GoTo Err_Go2Prev_Click
DoCmd.GoToRecord , , acPrevious
Exit_Go2Prev_Click:
Exit Sub

Err_Go2Prev_Click:
DoCmd.GoToRecord , , acLast
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
L

Linq Adams via AccessMonster.com

And for the "Henny Pennies" out there who will insist that the sky is falling
and this can possibly cause another type of error, this modification checks
for the specific error and runs the "wrap" code:
Private Sub Go2First_Click()
On Error GoTo Err_Go2First_Click
DoCmd.GoToRecord , , acFirst

Exit_Go2First_Click:
Exit Sub

Err_Go2First_Click:
MsgBox Err.Description
Resume Exit_Go2First_Click
End Sub

Private Sub Go2Next_Click()
On Error GoTo Err_Go2Next_Click
DoCmd.GoToRecord , , acNext
[ClientName].SetFocus
Exit_Go2Next_Click:
Exit Sub

Err_Go2Next_Click:
If Err.Number = 2105 Then
DoCmd.GoToRecord , , acFirst
Else
MsgBox Err.Description
Resume Exit_Go2Next_Click
End If
End Sub

Private Sub Go2Last_Click()
On Error GoTo Err_Go2Last_Click
DoCmd.GoToRecord , , acLast

Exit_Go2Last_Click:
Exit Sub

Err_Go2Last_Click:
MsgBox Err.Description
Resume Exit_Go2Last_Click
End Sub

Private Sub Go2Prev_Click()
On Error GoTo Err_Go2Prev_Click
DoCmd.GoToRecord , , acPrevious

Exit_Go2Prev_Click:
Exit Sub

Err_Go2Prev_Click:
If Err.Number = 2105 Then
DoCmd.GoToRecord , , acLast
Else
MsgBox Err.Description
Resume Exit_Go2Prev_Click
End If
End Sub

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
N

Nad

Many Thanks to Adams and Stuart.
Thanks Adams for giving the complete information.

U guys are very kind.
Regards
 

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