[AccessD] Duplicate code for nav buttons

Dan Waters dwaters at usinternet.com
Tue Apr 1 19:27:58 CDT 2008


Hi Arthur,

I've use the following code for several years with no problem.  It doesn't
address First or Last buttons, but I'm sure you can modify to suit.  Call
EDNextPrevious whenever the form might have moved to a new record.

The filed txtPPVPID holds the unique ID for the recordset this form is based
on.

'----------------------------------------------------------------

Private Sub EDNextPrevious()

    Dim lngPosition As Long

    If Me.Recordset.EOF = True Then
        '-- Empty table
        butPrevious.Enabled = False
        butNext.Enabled = False
    Else
        Me.RecordsetClone.MoveLast
        If IsNull(txtPPVPID) Then
            butPrevious.Enabled = True
            butPrevious.SetFocus
            butNext.Enabled = False
        Else
            lngPosition = Me.RecordsetClone.RecordCount -
Me.Recordset.AbsolutePosition
            Select Case lngPosition
                Case 1  '-- end of recordset
                    If Me.RecordsetClone.RecordCount = 1 Then
                        butPrevious.Enabled = False
                        butNext.Enabled = False
                    Else
                        butPrevious.Enabled = True
                        butPrevious.SetFocus
                        butNext.Enabled = False
                    End If
                Case Me.Recordset.RecordCount  '-- Beginning of recordset
                    butNext.Enabled = True
                    butNext.SetFocus
                    butPrevious.Enabled = False
                Case Else  '-- Middle of recordset
                    butPrevious.Enabled = True
                    butNext.Enabled = True
            End Select
        End If
    End If

    Exit Sub

End Sub

'---------------------------------------------------------------------------

HTH!
Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller
Sent: Tuesday, April 01, 2008 6:48 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Duplicate code for nav buttons

My client wants the nav buttons on top of the form not the bottom, so I have
created them. I don't have the Access Developer's Handbook handy, and have
forgotten the slick way to deduce whether you're on the first or last row in
a given table. I can think of a couple of ways to deduce this but I would
love it if someone already has this code handy so I don't have to
experiment. I want to disable the First and Previous buttons if you're on
the first record, and disable the Next and Last buttons if you're already
there, and the Next and Last buttons to recognize that I may just have added
a row.

TIA,
Arthur
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list