deleting a record from a continuous subform

G

Guest

I have a continuous subform. I want each record in the subform to have a
button that deletes the record. I tried doing this with DAO by opening a
recordset using a select statement to select the record whose button was
clicked and coding the following:

recordSet.Edit
recordSet.Delete
recordSet.Update

But on the update command it gives me a runtime error, something like:
"Update or CancelUpdate without AddNew or Edit"

How can I accomplish this? Thanks for any input.

-ndalton
 
G

Guest

That would certainly work, but I'm actually designing this database for a
bunch of users at my workplace. I've done away with the record selector,
along with other things, in favor of very user-friendly buttons and other
fancy gizmos to make it very easy for my users to accomplish what they want
(I find it's a good policy to assume that the users are dense and helpless).

Any way I can provide them a button and delete the record programatically?

Thanks

-ndalton
 
J

Jeff L

Here's some simple code that I use:

Dim Answer As Integer

Answer = MsgBox("Are you sure you wish to delete this record?",
vbYesNo)

If Answer = vbYes Then

DoCmd.RunSQL "Delete from YourTableName where ID = " & Me.ID
Me.Refresh

End IF
 
M

Marshall Barton

ndalton said:
I have a continuous subform. I want each record in the subform to have a
button that deletes the record. I tried doing this with DAO by opening a
recordset using a select statement to select the record whose button was
clicked and coding the following:

recordSet.Edit
recordSet.Delete
recordSet.Update

But on the update command it gives me a runtime error, something like:
"Update or CancelUpdate without AddNew or Edit"


This should work as a button's Click event procedure:

If Me.Dirty Then Me.Undo
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
 

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