Intelligent Navigation buttons

RexesOperator

Registered User.
Local time
, 22:36
Joined
Jul 15, 2006
Messages
604
I found this thread

http://www.access-programmers.co.uk/forums/showthread.php?t=44199&highlight=navigation

after doing a search and everything is working great.

I remember seeing code somewhere that turns the navigation buttons into "intelligent" buttons. Once you are at the end of a recordset, the "next" button is smart enough to wrap to the beginning of the record set and vice versa with the "previous" button. Can you point me to where I might have seen this code?
 
I would think it would be as easy as putting this in for your GoToNext button:

Code:
On Error GoTo err_handler

DoCmd.RunCommand acCmdRecordsGoToNext

Exit Sub

err_handler:
If err.Number = 2105 Then
     DoCmd.RunCommand acCmdRecordsGoToFirst
Else
     MsgBox err.Description, vbOKOnly, "Error " & err.Number
End If
End Sub

And the same for the go to previous but just with the commands changed.
 
After some more searching when it didn't work, I found out the line should be:

If err.Number <> 2105 Then

Otherwise it works a treat.

Ever notice how just when you think you're finished, something new crops up? I promise this is my last request until after the database is deployed! I have to actually do some data entry!
 
This is code I use in the current event of forms where i use custom buttons. It enables/disables the next and prev buttons as necessary.

Code:
Private Sub Form_Current()
Dim recClone As DAO.Recordset

Set recClone = Me.RecordsetClone()

If Me.NewRecord Then
    cmdNext.Enabled = False
    If recClone.RecordCount = 0 Then
        cmdPrevious.Enabled = False
    Else
        cmdPrevious.Enabled = True
    End If
Else
    If recClone.RecordCount = 0 Then
        cmdPrevious.Enabled = False
        cmdNext.Enabled = False
    Else
        'synchronize the current pointer in the two recordsets
  
        recClone.Bookmark = Me.Bookmark
  
        recClone.MovePrevious
        cmdPrevious.Enabled = Not (recClone.BOF)
        recClone.MoveNext
   
        recClone.MoveNext
        cmdNext.Enabled = Not (recClone.EOF)
        recClone.MovePrevious
    End If
End If
recClone.Close
End Sub
 

Users who are viewing this thread

Back
Top Bottom