If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Simple delete record action. How?
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 |
#2
|
|||
|
|||
Set the code for your command button like this:
Private Sub cmdWhatever_Click() CurrentDb.Execute "Delete * From tblMyTable Where ID =" & Me.cboID Me.Requery End Sub -- Arvin Meyer, MCP, MVP Microsoft Access Free Access downloads: http://www.datastrat.com http://www.mvps.org/access "Sam Kuo" .(donotspam) wrote in message ... 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 |
#3
|
|||
|
|||
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 Meyer" wrote: Set the code for your command button like this: Private Sub cmdWhatever_Click() CurrentDb.Execute "Delete * From tblMyTable Where ID =" & Me.cboID Me.Requery End Sub -- Arvin Meyer, MCP, MVP Microsoft Access Free Access downloads: http://www.datastrat.com http://www.mvps.org/access "Sam Kuo" .(donotspam) wrote in message ... 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 |
#4
|
|||
|
|||
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 "Arvin Meyer" wrote: Set the code for your command button like this: Private Sub cmdWhatever_Click() CurrentDb.Execute "Delete * From tblMyTable Where ID =" & Me.cboID Me.Requery End Sub -- Arvin Meyer, MCP, MVP Microsoft Access Free Access downloads: http://www.datastrat.com http://www.mvps.org/access "Sam Kuo" .(donotspam) wrote in message ... 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 |
#5
|
|||
|
|||
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 "Sam Kuo" .(donotspam) wrote in message ... 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 "Arvin Meyer" wrote: Set the code for your command button like this: Private Sub cmdWhatever_Click() CurrentDb.Execute "Delete * From tblMyTable Where ID =" & Me.cboID Me.Requery End Sub -- Arvin Meyer, MCP, MVP Microsoft Access Free Access downloads: http://www.datastrat.com http://www.mvps.org/access "Sam Kuo" .(donotspam) wrote in message ... 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 |
#6
|
|||
|
|||
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 -- Message posted via http://www.accessmonster.com |
#7
|
|||
|
|||
Thanks alot, Gary. It does work! Much appreciated
Regards, Sam "Gary Beale via AccessMonster.com" wrote: 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 -- Message posted via http://www.accessmonster.com |
#8
|
|||
|
|||
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 "Arvin Meyer" wrote: 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 "Sam Kuo" .(donotspam) wrote in message ... 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 "Arvin Meyer" wrote: Set the code for your command button like this: Private Sub cmdWhatever_Click() CurrentDb.Execute "Delete * From tblMyTable Where ID =" & Me.cboID Me.Requery End Sub -- Arvin Meyer, MCP, MVP Microsoft Access Free Access downloads: http://www.datastrat.com http://www.mvps.org/access "Sam Kuo" .(donotspam) wrote in message ... 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 |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
unable to delete a record | Befuddled | General Discussion | 1 | February 1st, 2005 08:08 PM |
corrupted record won't delete | neenmarie | Database Design | 2 | January 12th, 2005 03:29 PM |
Access 2002 Tab Form slips to next record when trying to delete re | Darla999 | Using Forms | 1 | January 5th, 2005 03:11 PM |
modify warning message | Wendy | General Discussion | 10 | September 9th, 2004 03:35 AM |
code to delete a record | BIG-DB | New Users | 2 | June 16th, 2004 01:52 AM |