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
|
|||
|
|||
Delete forms record and subforms record
Hello, I have a form frmVWI and a subform named frmVWISubfor. I have a button
on my form that deletes the record but not my subforms record. there is a field that is the same on both tables can my record be deleted thatway? My forms table tblVWI has a field named VWI and it is a PK. My subforms table tblJobSteps has a field named VWInum. I want to delete records from these to field from a button on my form. How is this done? Thanks! -- Thanks, Chad |
#2
|
|||
|
|||
Delete forms record and subforms record
"SoggyCashew" wrote in message
... Hello, I have a form frmVWI and a subform named frmVWISubfor. I have a button on my form that deletes the record but not my subforms record. there is a field that is the same on both tables can my record be deleted thatway? My forms table tblVWI has a field named VWI and it is a PK. My subforms table tblJobSteps has a field named VWInum. I want to delete records from these to field from a button on my form. How is this done? Thanks! The simplest way is to define the relationship between the tables (if you haven't done so already), and specify that the relationship is to "Cascade Deletes". That way, whenever a record is deleted from tblVWI, any related records in tblJobSteps will automatically be deleted, no matter how the tblVWI record is deleted, on this form or elsewhere. No code is required. If for some reason you can't use an enforced relationship here, and you must do it in code, you can capture the value of VWI before you delete that record, and then use that value in a delete query to delete all matching records in tblJobSteps. But bewa then you have to allow for the possibility that the user might back out of the original delete (if you allow the warning prompt to be displayed), and you won't want to delete the child records in that case. This is not hard to do, but it is important to get it right. I strongly recommend you just use the relationship & Cascade Deletes to let the database engine handle it. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#3
|
|||
|
|||
Delete forms record and subforms record
Thans you it worked perfectly... I didnt know that was there
-- Thanks, Chad "Dirk Goldgar" wrote: "SoggyCashew" wrote in message ... Hello, I have a form frmVWI and a subform named frmVWISubfor. I have a button on my form that deletes the record but not my subforms record. there is a field that is the same on both tables can my record be deleted thatway? My forms table tblVWI has a field named VWI and it is a PK. My subforms table tblJobSteps has a field named VWInum. I want to delete records from these to field from a button on my form. How is this done? Thanks! The simplest way is to define the relationship between the tables (if you haven't done so already), and specify that the relationship is to "Cascade Deletes". That way, whenever a record is deleted from tblVWI, any related records in tblJobSteps will automatically be deleted, no matter how the tblVWI record is deleted, on this form or elsewhere. No code is required. If for some reason you can't use an enforced relationship here, and you must do it in code, you can capture the value of VWI before you delete that record, and then use that value in a delete query to delete all matching records in tblJobSteps. But bewa then you have to allow for the possibility that the user might back out of the original delete (if you allow the warning prompt to be displayed), and you won't want to delete the child records in that case. This is not hard to do, but it is important to get it right. I strongly recommend you just use the relationship & Cascade Deletes to let the database engine handle it. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
Thread Tools | |
Display Modes | |
|
|