Append query with foreign key

vadharah

Registered User.
Local time
Today, 19:13
Joined
Oct 14, 2008
Messages
35
Hi Guys

really having a problem with the key violations

i have two tables with a one-many relationship:

CompanyDetails - (CompID(autonumber), Address, manager etc)
VanUse - (CompID(number), TypeoFVAn, FrequencyUse)

note the primary key of the 2nd table is made of all field including CompID from CompanyDetails.

Im trying to append 1 company and 3 vans they use.
My problem is when i run the append query it only appends records to the CompanyDetails table and for the second table i get a key violations error.

How to resolve the key problem....really need your help :-(
 
I don't understand foreign keys but why do you need one? what's wrong with...
tblCompany - CompanyID(autonumber, primary key), Name, Address etc.
tblVans - VanID(autonumber, primary key), CompanyID, Type, Number, etc.
Then one company (tblCompany.CompanyID) then has many vans (tblVans.CompanyID). The relationship is on CompanyID in both tables.

If your trying to append a record to the company table and at the same time append related records to the van table, this is not something I can speculate on. I have struggled with copying data from related tables and have to do it with messy but functional code. Maybe one of the very special people that patrol this forum will jump in and tell us both how.
 
Last edited:
I don't understand foreign keys but why do you need one? what's wrong with...
tblCompany - CompanyID(autonumber, primary key), Name, Address etc.
tblVans - VanID(autonumber, primary key), CompanyID, Type, Number, etc.
Then one company (tblCompany.CompanyID) then has many vans (tblVans.CompanyID). The relationship is on CompanyID in both tables.

If your trying to append a record to the company table and at the same time append related records to the van table, this is not something I can speculate on. I have struggled with copying data from related tables and have to do it with messy but functional code. Maybe one of the very special people that patrol this forum will jump in and tell us both how.

Thanx! i manged to do it by specifying in the CompanyID in the 2nd table as the same from the Companydetails and it worked fine. My problem was not specifyingwhere the CompanyID was comming from.
 

Users who are viewing this thread

Back
Top Bottom