473,472 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Add Data to table when linked with union query (MSACCESS)

106 New Member
I need some assistance with SQL query. I will be grateful if you can provide help please.

I have a database that records details of a road traffic accident and name of driver.
sub-form records names of passengers.
The two tables are related with a one-to-many relationship.

I need to view all the names (Drivers and Passengers) as datasheet view and be able to tick a box to show investigation for this particular person is complete.

I have made a union query that is able to list all names as I want them.
I made a third table 'CaseComplete', to hold the additonal information.
however, when linked, I cannot add data to the third table.
My SQL knowledge ends here. :)

tbl_Accident – This lists all drivers involved in an vehicle accident
tbl_acc_Passengers – This lists all passengers associated with the driver.
CaseComplete - This table is new table common to driver and passenger with additonal information related to the person (not the incident).
MMQ_Clients: Union Query

Below is my code:
Profesisonal assistance will be greatly appreciated.

Union Query
Expand|Select|Wrap|Line Numbers
  1. SELECT DRV.AccidentId, DRV.ContactID, DRV.AccidentRefFinal, DRV.SolRef
  2. FROM tbl_Accident AS DRV
  3. UNION ALL SELECT PASS.AccidentId, PASS.ContactID, PASS.PassRefFinal, PASS.SolRefP
  4. FROM tbl_Acc_Passengers AS PASS;
  5.  
Union Query Linked with CaseComplete
Expand|Select|Wrap|Line Numbers
  1. SELECT C.FirstName & " " & [SurName] AS Client, MMQ_Clients.SolRef, MMQ_Clients.AccidentId, MMQ_Clients.AccidentRefFinal, CaseComplete.CaseCompleteID, CaseComplete.AccidentID, CaseComplete.FileComplete, CaseComplete.DateComplete, CaseComplete.Reason
  2.  
  3. FROM Contacts AS C INNER JOIN (MMQ_Clients LEFT JOIN CaseComplete ON MMQ_Clients.AccidentId = CaseComplete.AccidentID) ON C.ContactID = MMQ_Clients.ContactID
  4.  
  5. ORDER BY MMQ_Clients.AccidentId DESC;
  6.  
Feb 16 '10 #1
5 2609
Delerna
1,134 Recognized Expert Top Contributor
Yes that happens when you join an uneditable query to an editable query. The whole thing becomes uneditable.

To illustrate what I mean
Create a query on a table
Expand|Select|Wrap|Line Numbers
  1. select * from thetable
  2.  
Open the query and the records are editable
Edit the query and make it a union of itself
Expand|Select|Wrap|Line Numbers
  1. select * from thetable
  2. union all
  3. select * from thetable
  4.  
now open the query again and it is uneditable (and it should be uneditable)
now if you join that query to another query that is editable
the other query is now also uneditable


you will need to rethink what you are doing
Feb 17 '10 #2
tasawer
106 New Member
I am still struggling with this issue. Let me put it this way. How can put the two tables together (editable and uneditable) so that I can add data to the editable table.

There must be a solution with coding.
Mar 1 '10 #3
Delerna
1,134 Recognized Expert Top Contributor
Of course there is a solution :)
My post wan't meant to discourage you suggesting it is hopeless.
All I meant is that you cannot join an uneditable query to an editable one and expect the result to be editable.

You need to rethink your problem and come up with another way other than using a union query

If I understand you correctly
You have a table to record an accident and the drivers
and a table to record the passengers.
Because of that you need to union the two tables so you can get all people involved.

You would have been better off with a table to record the accident details
and a table to record the people involved in the accident.
The table recording the people has a field that identifies whether the person is a driver or a passenger

That way you don't need to union the two tables to get the people involved and your query will remain editable.

There would be of couse ways to work around your current design. For example using the union in your query only makes the query uneditable. The tables are still editable and you could use vba code in a form to update the table directly rather than through the query.

I certainly don't recommend that approach.
My recommendation is that you research normalization and redesign your tables accordingly. Hopefully you are not too far along with your current design.
I think you probably actually need 3 tables instead of the two you have
Expand|Select|Wrap|Line Numbers
  1. tblAccident=AccidentID,Location,
  2.               Other fields directly relating to the accident       
  3. tblCars=AccidentID,CarRego,
  4.         Other fields directly relating to an individual car 
  5. tblPeople=AccidentID,CarRego,PersonType (Driver Passenger),
  6.             Other fields directly relating to an individual person
  7.  
Something like that anyway.
That way an accident can invole any number of cars
each car can have any number of people

Also case complete should relate to the accident and the person
What if the same person is involved in more than 1 accident?

Ultimately it is your database and your decision.
Mar 1 '10 #4
tasawer
106 New Member
This is a good suggestion.

however, my database is afully functional product with over 500 records.
NevertheIess, I shall think about redesigining as I beleive, VB coding will make it very complex.

Thanks for your help. It has been a useful suggestion.
Mar 1 '10 #5
Delerna
1,134 Recognized Expert Top Contributor
VB coding is actually critical to a well designed database and can actually make things simpler. There are many thing that just can't be done any other way. Having said that I believe it is a mistake to use it to side step tables that are not well designed. Anyway it's not so bad redesigning an active database so long as take it one step at a time and backup backup backup. I've done it before and no doubt I will do it again.

I generally create a completely new database for the new design and another database that has the one off task of copying the data from the current live version into my new version when it is ready to be released.
Mar 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: News | last post by:
Folks, I need help with this task. I have a set of data that needs to be plotted on timeline chart. Example: Unit ProcStart ProcEnd Machine U1 5/5/03 6:01 5/5/03 6:04 M1 U2 ...
2
by: Chris Becker | last post by:
I have the following query: SELECT Month, Sum(Hits) AS Hits FROM tblHits GROUP BY Month ORDER BY Month Unfortunately it only returns rows for months that have data assigned to them. How...
0
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
5
by: Sami | last post by:
I can create queries and reports based on info from one table. How do I create one using information from multiple tables. What do I need to make sure the information from one table will be...
6
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be...
3
by: Icemokka | last post by:
Hi, I've got a table in MsAccess with 100+ fields. If I fill a tabletable with this table , change some values , get the update-command via commandbuilder , the update fails. This because the...
9
by: karenjfrancis | last post by:
I have 4 Access databases, all with the same data model but different data. I want to build a front end that brings all of the data in the 4 databases together into one. Assuming my table of...
1
by: itisjitin | last post by:
Hi All, 1. Created table in SQL Server 2K with Primary key as int Identity 2. Link to table in MS Access 2K with child table 3. Using form in MSAccess to update the both master and child linked...
0
by: oskhan | last post by:
Hello Everyone, I have a little different problem and I though anyone might give me any idea that what is going wrong. I have a view which consists of 3 tables linked by UNION ALL, overall...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.