deleting a record from a continuous subform

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top