Deleting a record programatically

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
 
G

Graham Mandeno

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

Of course you will also need some error handling code :)
 
N

nathan harrison

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
 
D

Dan

Good Afternoon!

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

DoCmd.RunCommand acCmdDeleteRecord

Good Luck!
 
G

Graham Mandeno

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

....which is why I would never recommend anybody use the button wizard to
generate code :)
 
R

Rod Scoullar

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.
 

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