473,799 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ 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_Passeng ers – 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 2633
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
2987
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 5/5/03 6:03 5/5/03 6:05 M1 U3 5/5/03 6:03 5/5/03 6:04 M2 : etc. There are about 40K units and 30 serving machines. The data is in
2
7924
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 can I tweak this so that months 1-12 are returned, and Hits = 0 for months with no data in the base table?
0
3960
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, it began to have problems. Failure was observed only in a few PC's at first. For example, in an NT 4.0 SP6 PC, it continued to work OK. But in my Win 2k laptop, it failed. As the union query was gradually simiplified in testing, the failure...
0
2022
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 form by field named TestID. The subform is used just for displaying site address data, data which is stored in another table named Total_Site_Address. In the Total_Site_Address table there are numerous fields that form the site addresses...
5
38648
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 correctly assigned to specific person from another table? Thanks.
6
6375
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 able to take all of the data from the second column (B) of each worksheet and append that raw data to an access table. The columns in the spreadsheet do not have headers for use as field names (it's my assumption that my table should have a...
3
2007
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 commandbuilder adds a where clause that contains all the fields in the datatable ( to check whether the record has been changed since the fill ). Because MSAccess does not allow more then 99 fields in the where clause, the update fails offcourse.
9
2187
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 interest is called Removals, if I create linked tables I end up with Removals1, Removals2, Removals3 and Removals4. I could easily write a query to base a form or report upon to concatenate all of these tables' data into one view. However, the...
1
2011
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 table I want SQL server to automatically update the int identity column as it would normally. i.e. no need to enter a value even though it is a NOT NULL field. SQL Server recognises this , allows the row details to be entered without the int...
0
1793
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 all the three tables contains around 50 million, 2 million & 3 million respectively. Here is the view looks like: Create view test as Select * from tab1 // contains 50 million rows Union all Select * from tab2 // contains 50 million rows
0
9689
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.