Home

Deleting a Record

 

Description

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
                        .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
 
 
   
 

Home Copyright © 2009-2016, FunctionX, Inc.