Automating the display of a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

-- I am using a form to display a recordset of results which are derived
from a query.
I want the form to scroll through the recordset from top to bottom and then
return to the first value and repeat the process.
I can get this to work using the following code
Function macGoToNextRec()
On Error GoTo macGoToNextRec_Err

DoCmd.GoToRecord , "", acNext



macGoToNextRec_Exit:
Exit Function

macGoToNextRec_Err:
MsgBox Error$
Resume macGoToNextRec_Exit

End Function

My problem is that at the end of the recordset I get an error message saying
cannot move to the next record.
Question how can I bypass the message and get the code to loop back to the
first record and start again.
Help would be much appreciated.
Thanks
Dave
Dave Hawks
 
To the error capture you can add a check if a crtan error move to the first
record

Function macGoToNextRec()
On Error GoTo macGoToNextRec_Err

DoCmd.GoToRecord , "", acNext



macGoToNextRec_Exit:
Exit Function

macGoToNextRec_Err:
If Err = 2105 Then
DoCmd.GoToRecord , , acFirst
Else
MsgBox Err.Description
End If
Resume macGoToNextRec_Exit

End Function
 
Ofer
Thanks
I tried your code and still get the same error message after the focus moves
from the last record. i.e
"you cant go to the specified record"
"you may be at the end of the recordset"
 
I copied your code as follows;-
Function macGoToNextRec()
On Error GoTo macGoToNextRec_Err

DoCmd.GoToRecord , "", acNext



macGoToNextRec_Exit:
Exit Function

macGoToNextRec_Err:
If Err = 2105 Then
DoCmd.GoToRecord , "", acFirst
Else
MsgBox Err.Description
End If
Resume macGoToNextRec_Exit

End Function

The original code is shown in my first posting.
 
Put code break on the error capture, when the cursor is on this line "If Err
= 2105 Then" Press F9, run the form, before you'll get the error message the
code will stop in this point, check the Err number.
If it is a different number add it to the If statement.
If the code doesn't stop there, then the error occur somewhere else.

To check the error number, open the Immidiate window (Ctrl+G) write in it
?Err

Press Enter, and see which value returned.
 
Function macGoToNextRec()
On Error GoTo macGoToNextRec_Err
With Me
.RecordsetClone.MoveFirst
Do Until .RecordsetClone.EOF
.Bookmark = .RecordsetClone.Bookmark
DoEvents
.RecordsetClone.MoveNext
Loop
End With
macGoToNextRec_Exit:
Exit Function

macGoToNextRec_Err:
MsgBox Error$
Resume macGoToNextRec_Exit

End Function
 
Back
Top