|
Deleting a Record |
|
|
To remove a record in DAO, call the Delete()
method of the Recordset
class . Here is an example:
|
Private Sub cmdDeleteRecord_Click()
On Error GoTo cmdDeleteRecord_Error
Dim curDatabase As Object
Dim rstEmployees As Object
Dim fldEmployee As Object
Set curDatabase = CurrentDb
Set rstEmployees = curDatabase.OpenRecordset("Employees")
With rstEmployees
Do Until .EOF
For Each fldEmployee In .Fields
If fldEmployee.Name = "EmployeeNumber" Then
If fldEmployee.Value = "58-275" Then
' The record to be deleted has been found
.Delete
Exit For
End If
End If
Next
.MoveNext
Loop
End With
Exit Sub
cmdDeleteRecord_Error:
MsgBox "There was a problem when deleting the record."
End Sub
|
|