Deleting a Record



To remove a record in DAO, first locate that record. Then, call the Delete() method of the Recordset class . Here is an example:

Private Sub cmdDeleteRecord_Click()
On Error GoTo cmdDeleteRecord_Error

    Dim curDatabase As DAO.Database
    Dim rstEmployees As DAO.Recordset
    Dim fldEmployee As DAO.Field
    Set curDatabase = CurrentDb
    Set rstEmployees = curDatabase.OpenRecordset("Employees")
    With rstEmployees
        Do Until .EOF
            For Each fldEmployee In .Fields
                If fldEmployee.Name = "LastName" Then
                    If fldEmployee.Value = "Angoula" Then
                        ' The record to be deleted has been found
                        Exit For
                    End If
                End If
    End With
    Exit Sub

    MsgBox "There was a problem when deleting the record."
End Sub

Home Copyright © 2009-2015, FunctionX, Inc.