Delete row for a certain criteria : Recordset Add Update Delete « Access « VBA / Excel / Access / Word






Delete row for a certain criteria

 

Sub exaRecordsetDelete()
    Dim db As Database
    Dim rs As Recordset
    Dim DeleteCt As Integer
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Books Copy")
    
    DeleteCt = 0
    
    rs.MoveFirst
    Do While Not rs.EOF
       If rs!Price > 20 Then
             rs.Delete
             DeleteCt = DeleteCt + 1
       End If
       rs.MoveNext
    Loop
    
    rs.Close
    
    Debug.Print Format$(DeleteCt) & " records deleted."
End Sub

 








Related examples in the same category

1.Add new a row to recordset
2.Adding a New Record to a Recordset
3.Use AddNew and specify the field information
4.Use AddNew method from Recordset and two arrays to add a new row
5.Adding a New Record to a Table
6.Modifying a Record
7.Performing Batch Updates
8.Deleting a Record
9.Call update method from Recordset
10.Call delete method in Recordset
11.Check the Recordset affected