By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

Action when last record reached

P: n/a
Hello,

I have a subform that has a command button to move to the next record.
If there are more records i would just like to move to the next
record, When the last record is reached I would like an action to take
place (havent decided what yet).

I have not yet been able to get a Recordsetclone to work properly yet.

can someone please help me? Thanks! Gavin

Dim rst as recordset
set rst = Me.RecordsetClone
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePosition = lngPos then....

Nov 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Nov 1, 12:47 pm, gavm...@yahoo.com wrote:
Hello,

I have a subform that has a command button to move to the next record.
If there are more records i would just like to move to the next
record, When the last record is reached I would like an action to take
place (havent decided what yet).

I have not yet been able to get a Recordsetclone to work properly yet.

can someone please help me? Thanks! Gavin

Dim rst as recordset
set rst = Me.RecordsetClone
Dim lngPos As Long
rst.MoveLast
lngPos = rst.RecordCoutn
rst.FindFirst "ID = " & Me.ID
If rst.AbsolutePosition = lngPos then....
This should be your code for the 'Next Record' button:

Private Sub YourButtonName_Click()
On Error GoTo Err_YourButtonName_Click
DoCmd.GoToRecord , , acNext
Exit_YourButtonName_Click:
Exit Sub
Err_YourButtonName_Click:
'---Error Handling Code---
If Err.Number = 2105 Then 'User is already at the end of the recordset
MsgBox "You are already at the last record!"
Else
MsgBox "Error Number: " & Err.Number & " " & Err.Description
End If
Resume Exit_YourButtonName_Click
End Sub

This will display a custom message box rather than the cryptic Access
error message. Replace YourButtonName with the name on your button as
it is listed in the properties.

HTH,
Jana

Nov 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.