The Recordset's Delete method will delete a record from the underlying
data. Typically, you will want to take the record pointer to a different record after calling
the Delete method. Before moving the record pointer, you should check the RecordCount property
to make sure that at least one record is left in the Recordset.
After moving the record pointer, of course, you will need to check the Recordset's
EOF property to make sure you haven't moved beyond the end of the data. If you have,
you will want to call the MoveLast method—but first check the BOF property to make sure that
there are any records at all remaining in the Recordset. The code for these operations might
look like Listing 8.9.
LISTING 8.9
DELETING A RECORD
Private Sub cmdDelete_Click()
rsEmployees.Delete
rsEmployees.MoveNext
If rsEmployees.EOF Then
If rsEmployees.BOF Then
Msgbox ìNothing to Deleteî
cmdDelete.Enabled = False
Else
RsEmployees.MoveLast
End If
End If
End Sub
That particular example makes users aware of what they have done if they accidentally
tried to delete from a Recordset that contained no records.
See Also