473,394 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help deleting a record from a joined query in visual basic

I'm working on a database that someone else created. I have a form -
frm_main that is based on a query that is based on two tables. The
join is such that the first table tbl_JCN has all records included in
the query, but the second table tbl_SOC only has matching records
displayed. On the form (frm_main), there is a combo box - you can
make a selection and the form filters to display that record. There is
also a delete record button. When you click the button the record is
deleted from the first table - tbl_JCN, but not from the second table
(tbl_SOC). Here is the code that is executed when the delete record
button is clicked...

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

How can I adjust the code so the record is also deleted from the 2nd
table (tbl_SOC). I tried a round about approach without luck, so I"m
hoping someone can give me an easier, more direct solution. Thanks.
Dec 10 '07 #1
1 1706
The simplest way to do this would be with cascading delete.

In the Relationships window (Tools menu), create a relation by dragging the
key field from tbl_JCN and dropping it onto the matching field in tbl_SOC.
Access opens the Create Relation dialog. Check the boxes for Referential
Integrity (always), and Cascading Deletes (only when you really want this.)

Now when you delete a record in tbl_JCN, the matching record(s) in tbl_SOC
automatically delete. No additional code is needed.

BTW, that wizard-generated code for the Delete button is pretty horrid. This
might work better:

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then RunCommand acCmdDeleteRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Coll" <co*********@hotmail.comwrote in message
news:40**********************************@s8g2000p rg.googlegroups.com...
I'm working on a database that someone else created. I have a form -
frm_main that is based on a query that is based on two tables. The
join is such that the first table tbl_JCN has all records included in
the query, but the second table tbl_SOC only has matching records
displayed. On the form (frm_main), there is a combo box - you can
make a selection and the form filters to display that record. There is
also a delete record button. When you click the button the record is
deleted from the first table - tbl_JCN, but not from the second table
(tbl_SOC). Here is the code that is executed when the delete record
button is clicked...

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

How can I adjust the code so the record is also deleted from the 2nd
table (tbl_SOC). I tried a round about approach without luck, so I"m
hoping someone can give me an easier, more direct solution. Thanks.
Dec 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
4
by: XmlAdoNewbie | last post by:
Hi All, I am using Microsoft SQL Enterprise Manager version 8.0 and have created a view from a combination of 4 different tables. I would like to be able to go into sql and open the view and...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
20
by: Jack Schitt | last post by:
I thought I was starting to get a handle on Access, until I tried doing something useful...now I'm stuck. I have a DB with two tables - to keep it simple I'll say that one is an Employee File...
0
by: Niranjan | last post by:
Access XP Windows XP This code has been working for over 5 years with no problems and all of a sudden I am running into these wierd problems. I have this code to delete a record....
4
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
7
by: Stephen Poley | last post by:
I have the following situation: - a table of employees, keyed on employee-id; - a table of training sessions, keyed on session-id; - a requirement to log who was present at which session, plus...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.