Simple delete record action. How?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have created a button in a subform (with continuous form as the default
view).
I'd like to be able to click the button and delete the record. How may I do
that?

Regards,
Sam
 
Thanks, Arvin,

This is what I tried, but an error message says "Object doesn't support this
property or method". Where have I done wrong?

Private Sub cbDeleteAmend_Click()
' qryReidAmendedProductDrawings is the query in which the record is.
' No primary key is set in this query
' FormerDWGNo (text) is the Link Master/Child field to the main form
CurrentDb.Execute "Delete * From qryReidAmendedProductDrawings Where
FormerDWGNo =" & Me.cbDeleteAmend
Me.Requery
End Sub
 
Arvin, sorry I didn't read your line clear enough. The lines below are what I
really tried. I've however changed cboID to just ID because the records in
the subform are not filtered by combo box cboID.
The code would now delete ALL records with the same ID. But can I really
just delete any one record at a time? (because both textbox controls and the
button are in the subform's Detail section, and the subform is in continuous
form view, so for every record there's a delete button to be used to delete
that particular record)

Private Sub cmdWhatever_Click()
CurrentDb.Execute "Delete * From tblMyTable Where ID ='" & Me.ID & "'"
Me.Requery
End Sub

Regards,
Sam
 
Without a unique identifier for that record, you cannot delete just that
record using code. Is your unique id a text field? (your use of quotes
suggest that). Are you sure you are using the Primary Key for that record in
that table? (Your post suggests you are using the foreign key).
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
I have just such a button on one of my forms. It is located in a subform
which is set to Continuous forms. The button should be placed within the
continuous form itself, not in the header. The code is very simple:

Recordset.Delete

I know it sounds like it should delete the entire recordset, but it
doesn't. It just deletes the record within which the button resides.

Regards,

Gary
 
Hi Arvin,

Yes, my unique id is textbox
No, I'm not using the Primary Key. I use the foreign key.

So how do these determine what the lines should look like? (Please bear with
me because I don't have a good background in code writing)

But Gary's suggestion seems to work great in my situation. That is:
Recordset.Delete

Regards,
Sam
 
Back
Top