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 » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Delete forms record and subforms record



 
 
Thread Tools Display Modes
  #1  
Old February 2nd, 2010, 05:55 PM posted to microsoft.public.access.gettingstarted
SoggyCashew
external usenet poster
 
Posts: 108
Default 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  
Old February 2nd, 2010, 06:05 PM posted to microsoft.public.access.gettingstarted
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default 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  
Old February 2nd, 2010, 06:23 PM posted to microsoft.public.access.gettingstarted
SoggyCashew
external usenet poster
 
Posts: 108
Default 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

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


All times are GMT +1. The time now is 05:35 AM.


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