Solved Append Query Key Violation (1 Viewer)

JED25

New member
Local time
Today, 05:11
Joined
Apr 29, 2022
Messages
11
I'm fairly new to Access and I'm trying to build a client admission DB for my company by condensing an excessive amount of spreadsheets. I have a table where I'm compiling all the data, a linked table to an excel sheet where I manipulate past data, and created an append query. Every time I run the append query I get a key violation error for some of the data. My most recent attempt I tried to add 284 records, but only 84 appended correctly. Why won't it take all my data? I've already check that records are formatted correctly. None of my fields are indexed. The data shows up perfectly when I go to datasheet view. I'm completely at a loss.

Here is the SQL for the append query:

INSERT INTO [INTAKE LOG] ( ADMISSION, [CLT ID], INSURANCE, [LGL-ST], [REF BY], LOC, DISCHARGE, [CLT TYPE] )
SELECT [INTAKE LINK].ADMISSION, [INTAKE LINK].[CLT ID], [INTAKE LINK].INS, [INTAKE LINK].[LGL-ST], [INTAKE LINK].[REF BY], [INTAKE LINK].Loc, [INTAKE LINK].DISCHARGE, [INTAKE LINK].[CLT TYPE]
FROM [INTAKE LINK] LEFT JOIN [INTAKE LOG] ON [INTAKE LINK].ADMISSION = [INTAKE LOG].ADMISSION
WHERE ((([INTAKE LOG].ADMISSION) Is Null));
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:11
Joined
Oct 29, 2018
Messages
21,455
Hi. Welcome to AWF!

Key violations usually refer to index requirements. It would be hard to tell you what's wrong, if we can't see the actual database file with the problematic data included.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:11
Joined
Feb 19, 2002
Messages
43,233
A key violation is pretty specific.
 

JED25

New member
Local time
Today, 05:11
Joined
Apr 29, 2022
Messages
11
I can't really send the DB due to HIPPA violations (I work in a hospital setting). However, I have looked up the indexes and there is nothing indexed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:11
Joined
Sep 21, 2011
Messages
14,238
You are not the only one who has this kind of thing
Just replace sensitive data with meaningless text by using update queries.
On a copy of your db as well.
I seem to recall @moke123 created some functions to obfuscate the data.
See the link in my signature. ( which is not visible on phone?) :(
 

moke123

AWF VIP
Local time
Today, 05:11
Joined
Jan 11, 2013
Messages
3,912
On a copy of your db as well.
I seem to recall @moke123 created some functions to obfuscate the data.
See the link in my signature. ( which is not visible on phone?) :(

here it is

 

Gasman

Enthusiastic Amateur
Local time
Today, 10:11
Joined
Sep 21, 2011
Messages
14,238
here it is

Yes, I have a link in my signature. Just it's not visible on my phone.
 

JED25

New member
Local time
Today, 05:11
Joined
Apr 29, 2022
Messages
11
Ok I actually created a copy of my database and removed a bunch of thing and consolidated the information.
 

Attachments

  • Master Data Entry - Copy.accdb
    4.9 MB · Views: 229

Eugene-LS

Registered User.
Local time
Today, 12:11
Joined
Dec 7, 2018
Messages
481
Ok I actually created a copy of my database and removed a bunch of thing and consolidated the information.
И где Excel файл - А! ???
Вы думаете - или нет? ... :(
...
EN:
And where is the Excel file - Ah! ???
Do you think - or not? ...
 

JED25

New member
Local time
Today, 05:11
Joined
Apr 29, 2022
Messages
11
Ok I actually created a copy of my database and removed a bunch of thing and consolidated the information.
И где Excel файл - А! ???
Вы думаете - или нет? ... :(
...
EN:
And where is the Excel file - Ah! ???
Do you think - or not? ...
 

Attachments

  • MASTER DATA EXPORT TEST.zip
    347.8 KB · Views: 217

Eugene-LS

Registered User.
Local time
Today, 12:11
Joined
Dec 7, 2018
Messages
481
@JED25 - query works:
SQL:
INSERT INTO [INTAKE LOG] ( ADMISSION, [CLT ID], INSURANCE, [REF BY], LOC, DISCHARGE )
SELECT [INTAKE LINK].ADMISSION, [INTAKE LINK].[CLT ID], [INTAKE LINK].INS,
    [INTAKE LINK].[REF BY], [INTAKE LINK].Loc, [INTAKE LINK].DISCHARGE
FROM [INTAKE LINK]
    LEFT JOIN [INTAKE LOG]
        ON [INTAKE LINK].ADMISSION = [INTAKE LOG].ADMISSION
WHERE ([INTAKE LOG].ADMISSION Is Null);
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:11
Joined
Feb 28, 2001
Messages
27,148
There are only a couple of things that would stop the updates. One of them is indexing, but you say no fields are indexed. The other is that for some reason, there is a constraint on the fields. If you have a linked table based on the Excel file, there should still be a table definition for the external file and field definitions should still be associated with the linked table. Check for field-level constraints such as "required" (="YES") or "ZLS allowed" (="NO").

I am somewhat confused, though. Which version of Office are you using? I ask because some versions of Office do not support updating linked Excel tables. For those versions, Excel tables are read-only. If it does updates at all, obviously it is not one of those versions - but then, which version is it? Knowing that MIGHT make a difference.
 

JED25

New member
Local time
Today, 05:11
Joined
Apr 29, 2022
Messages
11
There are only a couple of things that would stop the updates. One of them is indexing, but you say no fields are indexed. The other is that for some reason, there is a constraint on the fields. If you have a linked table based on the Excel file, there should still be a table definition for the external file and field definitions should still be associated with the linked table. Check for field-level constraints such as "required" (="YES") or "ZLS allowed" (="NO").

I am somewhat confused, though. Which version of Office are you using? I ask because some versions of Office do not support updating linked Excel tables. For those versions, Excel tables are read-only. If it does updates at all, obviously it is not one of those versions - but then, which version is it? Knowing that MIGHT make a difference.
I have 2016
@JED25 - query works:
SQL:
INSERT INTO [INTAKE LOG] ( ADMISSION, [CLT ID], INSURANCE, [REF BY], LOC, DISCHARGE )
SELECT [INTAKE LINK].ADMISSION, [INTAKE LINK].[CLT ID], [INTAKE LINK].INS,
    [INTAKE LINK].[REF BY], [INTAKE LINK].Loc, [INTAKE LINK].DISCHARGE
FROM [INTAKE LINK]
    LEFT JOIN [INTAKE LOG]
        ON [INTAKE LINK].ADMISSION = [INTAKE LOG].ADMISSION
WHERE ([INTAKE LOG].ADMISSION Is Null);
Ok this really doesn't make sense because it does work on the copy, but not the original. So something I changed must be causing the problem.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:11
Joined
Oct 29, 2018
Messages
21,455
Here's your original query from your first post.
Here is the SQL for the append query:

INSERT INTO [INTAKE LOG] ( ADMISSION, [CLT ID], INSURANCE, [LGL-ST], [REF BY], LOC, DISCHARGE, [CLT TYPE] )
SELECT [INTAKE LINK].ADMISSION, [INTAKE LINK].[CLT ID], [INTAKE LINK].INS, [INTAKE LINK].[LGL-ST], [INTAKE LINK].[REF BY], [INTAKE LINK].Loc, [INTAKE LINK].DISCHARGE, [INTAKE LINK].[CLT TYPE]
FROM [INTAKE LINK] LEFT JOIN [INTAKE LOG] ON [INTAKE LINK].ADMISSION = [INTAKE LOG].ADMISSION
WHERE ((([INTAKE LOG].ADMISSION) Is Null));
Here's the working query from @Eugene-LS from post #17.
@JED25 - query works:
SQL:
INSERT INTO [INTAKE LOG] ( ADMISSION, [CLT ID], INSURANCE, [REF BY], LOC, DISCHARGE )
SELECT [INTAKE LINK].ADMISSION, [INTAKE LINK].[CLT ID], [INTAKE LINK].INS,
    [INTAKE LINK].[REF BY], [INTAKE LINK].Loc, [INTAKE LINK].DISCHARGE
FROM [INTAKE LINK]
    LEFT JOIN [INTAKE LOG]
        ON [INTAKE LINK].ADMISSION = [INTAKE LOG].ADMISSION
WHERE ([INTAKE LOG].ADMISSION Is Null);
They are not exactly the same. As far as I can see, the second/working query is missing two fields from your original query.
 

Users who are viewing this thread

Top Bottom