PC Review


Reply
Thread Tools Rate Thread

Delete forms record and subforms record

 
 
SoggyCashew
Guest
Posts: n/a
 
      2nd Feb 2010
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
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      2nd Feb 2010
"SoggyCashew" <(E-Mail Removed)> wrote in message
news:0601FE06-6B8C-437D-902F-(E-Mail Removed)...
> 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 beware: 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)

 
Reply With Quote
 
SoggyCashew
Guest
Posts: n/a
 
      2nd Feb 2010
Thans you it worked perfectly... I didnt know that was there
--
Thanks,
Chad


"Dirk Goldgar" wrote:

> "SoggyCashew" <(E-Mail Removed)> wrote in message
> news:0601FE06-6B8C-437D-902F-(E-Mail Removed)...
> > 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 beware: 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)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 subforms only one clears its record when new record selected naigy via AccessMonster.com Microsoft Access VBA Modules 9 10th Jul 2006 02:27 AM
Synchronizing forms/subforms to display the same record =?Utf-8?B?Tmljbw==?= Microsoft Access Forms 3 7th Nov 2005 11:47 PM
Open forms AND SUBFORMS on new record Kurt Microsoft Access Form Coding 4 1st Apr 2005 09:29 PM
Open sub forms with linked record if it exists, otherwise a new record aeilie Microsoft Access Form Coding 5 30th Nov 2004 02:57 PM
Forms and Subforms.... expanding does not change the selected record (Datasheet view) Chris Underwood Microsoft Access Form Coding 1 22nd Jun 2004 02:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 PM.