Deleting Records

J

Jim

This is too simple but I'm having a lot of trouble trying to do this.
I can create a recordset using DoCmd.ApplyFilter Sql (Sql contains the Sql
statement)
I can delete a single record using DoCmd.DomenuItem acFormBar, acEditmenu,
8, acmenuVer70
I want to delete all the records in the recordset but I can't make it happen.
I tried DoCmd.RunSql, and everything else I can think of. I'm doing
something wrong.
Can anyone give me a bit of code showing how to delete all the records in
the recordset.

Thanks
 
A

Allen Browne

The simplest way to do this would be to execute a DELETE query statement.

It sounds like you know how to build a query to use for filtering, so you
know how to build the WHERE clause to identify the records to delete. All
you need is something like this:
Dim strSql As String
strSql = "DELETE FROM Table1 WHERE (SomeField = 99);"
dbEngine(0)(0).Execute strSql, dbFailOnError

If Execute is new, see:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
 

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.

Ask a Question

Top