Deleting an Existing Record from Recordset : Recordset Delete « Access « VBA / Excel / Access / Word






Deleting an Existing Record from Recordset

 
Sub DeleteCusts(lngProjEst As Long)
    Dim intCounter as Integer
    Dim rst As ADODB.Recordset
    Set rst = New ADODB.Recordset
    rst.ActiveConnection = CurrentProject.Connection
    rst.CursorType = adOpenDynamic
    rst.LockType = adLockOptimistic
    rst.Open "Select * from Products "

    intCounter = 0
    Do Until rst.EOF
        If rst("UnitPrice") < lngProjEst Then
            rst.Delete
            intCounter = intCounter + 1
        End If
        If Not rst.EOF Then
            rst.MoveNext
        End If
    Loop
    Debug.Print intCounter & " Customers Deleted"
    rst.Close
    Set rst = Nothing
End Sub  

 








Related examples in the same category

1.Removing a Table Using Code