Deleting a record programatically

  • Thread starter Thread starter J.C.
  • Start date Start date
J

J.C.

This is way too simple, but the answer eludes me.

I have a form with the RecordSet set to a query. I want
to program a button to delete the current record. How?

jc
 
Put the following code in your button's Click event procedure:
DoCmd.RunCommand acCmdDeleteRecord

Of course you will also need some error handling code :-)
 
Hi J.C.,

there are several ways to accomplish deleting records. for just straight
forward easy, the button wizard can create the delete record action for you.
it will create something in code like:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

you can also create a recordset and use brute force with a rs.delete
command. and then there is SQL.

so, depending on what you need and how complicated, there are many options.
based on what you wrote, i say the wizard way might be the easiest.

Good Luck...

Nathan
Senior Test Lead
www.skylineprints.com
 
Good Afternoon!

There are several ways to do this. One simple way is
listed below:

DoCmd.RunCommand acCmdDeleteRecord

Good Luck!
 
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , **acMenuVer70**

....which is why I would never recommend anybody use the button wizard to
generate code :-)
 
The docmd.runcommand suggestions are correct.

Just be careful when deleting records from a query rather than a table if
the query involves joined tables. On occasions records from more than one
joined table are deleted.

Rod Scoullar.
 
Back
Top