Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return to First Record After Cycle 2

Status
Not open for further replies.

pmo

Technical User
Jan 15, 2001
76
AU
I am very green with access and really only using macros at present.
I am wanting to cycle through all of my records in form view. I have been able to do this with a simple GotoRecord Next on a timer. The problem is when it cycles through all records I get an error because it is at the end of the recordset and can't find the next. This is where I want it to go back to the first record and start again.
Any help is appreciated.
 
How are ya pmo . . .

In your macro you need a [blue]condition[/blue] to goto the first record if your on the last. Something like:
Code:
[blue][Forms].[[purple][b]FormName[/b][/purple]].[CurrentRecord]=[Forms].[[purple][b]FormName[/b][/purple]].[Recordset].[RecordCount][/blue]
Your next macro line would be your [blue]goto next[/blue] command.

This is much better done with VBA and I'd perfer you wasted your timing there instead of with macros. Its a bigger easier world once you understand it.

BTW ... What are you doing with the records as you cycle thru them?

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks TheAceMan1,
I am not even sure how i would put your suggestion into a macro.
I have workied out how to create a procedure..It looks like this-

Private Sub Form_Timer()
DoCmd.GoToRecord , , acNext

End Sub

How would I add the line that checks if it is the last record than returns to the first?


The purpose is to have like a screen show of information that continually rotates around on the screen. No action has to take place.

Thanks for the help.
 
You may try something like this:
Code:
Private Sub Form_Timer()
With Me.Recordset
  If .EOF Then
    .MoveFirst
  Else
    .MoveNext
  End If
End With
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV and TheAceMan1,
It works perfectly. I would like to think I could assist you one day but at my skill level it is unlikely.
Thanks Again
 
pmo . . .

There is a big difference between [blue]a macro[/blue] and [blue]VBA[/blue]. What you revealed was VBA, not a macro. At least for me, [blue]calling VBA a macro is very missing leading.[/blue]

I'm not trying to sound this way or that, but for future reference you should know the difference when you speak of it.

Cheers! [thumbsup2]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thankyou.
All is working well, the database moves to each record in order then starts at the beginning when required.
Is there a way that the VBA can be changed so that the next record that is chosen is random and not in the order of the query that feeds it? Whilst it works this would improve its functionality significantly.

PMO
 
pmo . . .

If your going to use [blue]random selection[/blue] then you don't need the last record turnover. The following should do:
Code:
[blue]   Dim idx As Long
   
   Randomize
   
   idx = Int(Me.Recordset.RecordCount * Rnd + 1)
   Me.Recordset.AbsolutePosition = idx - 1[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks AceMan1...You are brilliant.
It works perfectly. Thanks for your help.

I don't necessarily fully understand the code...but it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top