Append query not working (1 Viewer)

Bindy68

New member
Local time
Today, 19:08
Joined
May 6, 2019
Messages
4
Hi

Sorry I'm a bit of an Access dunce sometimes - (and don't do the complicated programming stuff :)) - I'm trying to run an append query to add some records to another table.

Ref No - short text
Stock Code - short text
Quantity - long integer

Both tables only have three fields as above and the field types are the same. The table I'm trying to append to however has the first two fields as key fields and the table I'm appending from doesnt.

The information I am trying to append does not appear in the destination table already and the source data does not seem to contravene the rules set by the two key fields in the destination table?

However I'm getting key violations so they wont append?

I suspect it may be because I've got some pretty complicated relationships between tables and this may be behind it?

Any ideas for how i can run this append query - will be part of a macro eventually???

Thanks!
 

June7

AWF VIP
Local time
Today, 10:08
Joined
Mar 9, 2014
Messages
5,475
If you are getting key violations then obviously the data is in violation. What do you mean by 'complicated' relationships?

Post the attempted SQL statement. If you want to provide db for analysis, follow instructions at bottom of my post.
 

Bindy68

New member
Local time
Today, 19:08
Joined
May 6, 2019
Messages
4
The SQL statement is:

INSERT INTO [Movements-Detail] ( [Ref No], Stockcode, Quantity )
SELECT [Temp Write Back].[Ref No], [Temp Write Back].[Component Stockcode], [Temp Write Back].Required
FROM [Temp Write Back];
 

Bindy68

New member
Local time
Today, 19:08
Joined
May 6, 2019
Messages
4
See attached for zipped db.
 

Attachments

  • StockBeast v2.zip
    1.4 MB · Views: 197

June7

AWF VIP
Local time
Today, 10:08
Joined
Mar 9, 2014
Messages
5,475
Why do you need to copy records?

When I try to manually enter those data into Movements-Detail, get error message 'related record required in Movements-Main'.

Main has a [Ref No] 1 and Back has [Ref No] "WO1". Attempt to save "WO1" into Details violates referential integrity.

I would not set compound primary keys because they are not saved as compound foreign keys, just set compound index.

Advise not to use spaces nor punctuation/special characters in naming convention, nor reserved words as names.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:08
Joined
Feb 28, 2001
Messages
27,192
Your DB has a compound PK across the fields [Ref No] and [StockCode], so the immediate thought would be a key violation. However, you do not show unique keys on the individual fields so duplicating a [Ref No] (which your temp table table does) shouldn't kick it out. And the records already in the detail table don't appear to conflict with the records in the temp table. Therefore, I understand your confusion.

But there IS a sort of "gotcha" trap that you fell into. Field [Required] matches an Access reserved word and this situation has been known to trip Access up very quickly. Can you try to change that field name and see if something different happens?
 

Users who are viewing this thread

Top Bottom