strSQL = DELETE * FROM SomeTable WHERE keyfield = " & Me.txtKeyField & ";"
Currentdb.Execute(strSQL), dbFailOnError
Me.Requery
SomeTable would be the table or query that is the same as the record source
of your form. keyfield would be the primary key field of the table and
Me.txtKeyField would be the control on the form that is bound to keyfield.
If you don't have the keyfield bound to a control on your form, you could
use the field in the form's recordset:
strSQL = DELETE * FROM SomeTable WHERE keyfield = " &
Me.Recordset![keyfield] & ";"
The only difference to delete multiple rows would be to write the WHERE
clause to include the records you want deleted.
Note the Me.Requery is important in that you are deleting from the
underlying table and the Requery will also remove them from the form's
recordset.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.