How to delete selected record on subform with delete button? (1 Viewer)

smile

Registered User.
Local time
Today, 05:02
Joined
Apr 21, 2006
Messages
212
Please see attached db example.

View forms tbl_type and tbl_type1

First is made with listbox second with subform.

My problem is that I can't find out how to:

How to delete selected record on subform with delete button?
Why right click delete is disabled on subform?

Thanks.
 

Attachments

  • modify_data.zip
    43.2 KB · Views: 631

John Big Booty

AWF VIP
Local time
Today, 23:02
Joined
Aug 29, 2005
Messages
8,263
Firstly having a form and a table both called tbl_type is very confusing, and will cause you no end of grief latter on. A form should be called frm_type, a query qry_type and a report rpt_type. This way it will be abundantly clear what type of object you are referring to. Also avoid using spaces and other special character (!@#$%^&*+-?<>:;"') in object names underscore is fine though.

As presented your forms do not make a lot of sense as both the form and sub form have the same table as a control source.

If the sub form is set to DataSheet view (as presented) then I had no problem with using right click to delete a record.

Perhaps you could briefly outline what you are trying to achieve with this DB and it may make a little more sense to me.
 

missinglinq

AWF VIP
Local time
Today, 08:02
Joined
Jun 20, 2003
Messages
6,423
As John said, this doesn't make a lot of sense, with the main form and the subform having the same recordsource! Perhaps if you could give some information on exactly what you're trying to accomplish here someone can give you some informed guidance.

As to why the "right-click delete" is disabled on the subform, the answer is that it isn't! You just have to click on the record in question to select it, then right-click and delete it! The fact that the arrow appears to the left of the row doesn't mean that that record is selected.

The Delete button you have on your form resides on the main form, not the subform, and so it'll delete the current record on the main form, not in the current record on the subform.
 

smile

Registered User.
Local time
Today, 05:02
Joined
Apr 21, 2006
Messages
212
Firstly having a form and a table both called tbl_type is very confusing, and will cause you no end of grief latter on. A form should be called frm_type, a query qry_type and a report rpt_type. This way it will be abundantly clear what type of object you are referring to. Also avoid using spaces and other special character (!@#$%^&*+-?<>:;"') in object names underscore is fine though.

As presented your forms do not make a lot of sense as both the form and sub form have the same table as a control source.

If the sub form is set to DataSheet view (as presented) then I had no problem with using right click to delete a record.

Perhaps you could briefly outline what you are trying to achieve with this DB and it may make a little more sense to me.

I know about correct naming, sorry was in a hurry just made a sample db using the wizard ant it named my form as tbl because it was created from table.

Just trying to understand the correct way to delete selected items using a button. I need to be able to delete from listbox and subform as sometimes I need the form to display multi-column data.

How were you able to delete using right click? I see it grayed out.

I was able to delete on subform using:

I also rename my tbl_type subform to tbl_type_subform

PHP:
    Me.tbl_type_subform.Form.Recordset.Delete
    Me.tbl_type_subform.SetFocus

And on listbox:

I have tried this code and it seems to work:

PHP:
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordSet("Select * from [tbl_type]")
rs.FindFirst "[ID] =" & Me!List3
rs.Delete
Me.List3.Requery

Se attachment for my updated db
 

Attachments

  • modify_data1.zip
    100.1 KB · Views: 550

smile

Registered User.
Local time
Today, 05:02
Joined
Apr 21, 2006
Messages
212
As John said, this doesn't make a lot of sense, with the main form and the subform having the same recordsource! Perhaps if you could give some information on exactly what you're trying to accomplish here someone can give you some informed guidance.

As to why the "right-click delete" is disabled on the subform, the answer is that it isn't! You just have to click on the record in question to select it, then right-click and delete it! The fact that the arrow appears to the left of the row doesn't mean that that record is selected.

See my attached image
The Delete button you have on your form resides on the main form, not the subform, and so it'll delete the current record on the main form, not in the current record on the subform.

So how do make it work? Is my solution on post 5 correct?
 

Attachments

  • delete1.png
    delete1.png
    13.5 KB · Views: 639

John Big Booty

AWF VIP
Local time
Today, 23:02
Joined
Aug 29, 2005
Messages
8,263
For some reason I have not yet discovered the Delete on right click is disabled when the DB is run under Access '07.

Have a look at the attached, for a couple of solutions.
 

Attachments

  • db1.zip
    553 KB · Views: 677

missinglinq

AWF VIP
Local time
Today, 08:02
Joined
Jun 20, 2003
Messages
6,423
It's not disabled when I run it under Access 2003 (SP2) either, hence my comment.
 

smile

Registered User.
Local time
Today, 05:02
Joined
Apr 21, 2006
Messages
212
Hmm, I now see that becaue this code

PHP:
Dim rs As Recordset 
Set rs = CurrentDb.OpenRecordSet("Select * from [tbl_type]") 
rs.FindFirst "[ID] =" & Me!List3 
rs.Delete 
Me.List3.Requery

works with recordset the normal undo button does not work.

How can make a pop-up to instruct the user that this actions can't be undone? So the user can click yes or no.

And perhaps there is code to make the undo button work?

Thanks for your help.

I have only access 07 and the right click delete is disabled. I have no other access versions so can't check.
 

Users who are viewing this thread

Top Bottom