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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop from last record to first recode

Status
Not open for further replies.

databaser

MIS
Feb 11, 2007
9
US
I creaded a move next and a move previous command buttons. I want the move next to go to the first record when it moves past the last record and not to a new record and visa versa on the move previous.
 
How are ya databaser . . .

In the code module of the form copy/paste the following routine:
Code:
[blue]Public Sub NextRec(movNext As Boolean)
   Dim rst As DAO.Recordset
   
   Set rst = Me.RecordsetClone
   
   If rst.BOF Then
      MsgBox "No Records . . . Can't Move!"
   Else
      If movNext Then
         rst.MoveNext
         If rst.EOF Then rst.MoveFirst
      Else
         rst.MovePrevious
         If rst.BOF Then rst.MoveLast
      End If
      
      Me.Bookmark = rst.Bookmark
   End If
   
   Set rst = Nothing
      
End Sub[/blue]
Next . . . in the [blue]Click[/blue] event of the [blue]Move Next[/blue] button copy/paste the following . . .
Code:
[blue]   Call NextRec(True)[/blue]
. . . and the same event in the [blue]Move Previous[/blue] button:
Code:
[blue]   Call NextRec(False)[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top