Write the Database Navigation Events


The modified User Interface hides the Data Control, and replaces the Navigation Control with code triggered by Command Button Click Events

UI2.jpg (15124 bytes)

 

Option Explicit

Private Sub cmdFirst_Click()
    dtaAddress.Recordset.MoveFirst

End Sub

Private Sub cmdLast_Click()
    dtaAddress.Recordset.MoveLast

End Sub

Private Sub cmdNext_Click()
    dtaAddress.Recordset.MoveNext

End Sub

Private Sub cmdPrev_Click()
    dtaAddress.Recordset.MovePrevious

End Sub

Running the program allows you to move between records and the updates still function, but some additional logic is necessary to handle the EOF and BOF conditions and you can no longer add new rows to the table (Even though EOFAction is still set to AddNew)

Modify the cmdNext and cmdPrev  to handle these conditions

Private Sub cmdNext_Click()
    dtaAddress.Recordset.MoveNext
    If dtaAddress.Recordset.EOF Then
        dtaAddress.Recordset.MoveLast
    End If

End Sub

Private Sub cmdPrev_Click()
    dtaAddress.Recordset.MovePrevious
    If dtaAddress.Recordset.BOF Then
        dtaAddress.Recordset.MoveFirst
    End If

End Sub

You can customize this logic anyway you want. Perhaps when you hit EOF is True, you perform a MoveFirst and "wrap" back to the first record.

Download the Completed Example


Back to Week 12