A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Simple delete record action. How?



 
 
Thread Tools Display Modes
  #1  
Old April 6th, 2005, 01:49 PM
Sam Kuo
external usenet poster
 
Posts: n/a
Default 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  
Old April 6th, 2005, 02:14 PM
Arvin Meyer
external usenet poster
 
Posts: n/a
Default

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  
Old April 6th, 2005, 03:01 PM
Sam Kuo
external usenet poster
 
Posts: n/a
Default

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  
Old April 7th, 2005, 11:21 AM
Sam Kuo
external usenet poster
 
Posts: n/a
Default

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  
Old April 7th, 2005, 12:17 PM
Arvin Meyer
external usenet poster
 
Posts: n/a
Default

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  
Old April 7th, 2005, 12:40 PM
Gary Beale via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

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  
Old April 8th, 2005, 11:41 AM
Sam Kuo
external usenet poster
 
Posts: n/a
Default

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  
Old April 8th, 2005, 11:47 AM
Sam Kuo
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 12:38 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.