Action when last record reached
am 01.11.2007 20:47:40 von gavm360
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....
Re: Action when last record reached
am 07.11.2007 20:48:45 von Jana
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