Results 1 to 3 of 3
  1. #1
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51

    Append query, problem with key violation

    Hello



    I'm trying to run an append query, but I keep getting key violations. I'm trying to update the field SaneringmetKode in ProjektDelledning using DelledningsID as a join criteria.

    Code:
    INSERT INTO ProjektDelledning ( ProjektID, DelledningID, SaneringsmetKode, DatoOprettet, DatoOpdateret )
    
    SELECT  ProjektDelledning.ProjektID, ProjektDelledning.DelledningID,  NySaneringsData.SaneringsmetodeKode AS SaneringsmetKode,  Nz([ProjektDelledning].[DatoOprettet],Now()) AS DatoOprettet,  Nz([ProjektDelledning].[DatoOpdateret],Now()) AS DatoOpdateret
    
    FROM NySaneringsData INNER JOIN ProjektDelledning ON NySaneringsData.DelledningsID = ProjektDelledning.DelledningID
    
    WHERE  (((Exists (SELECT * FROM ProjektDelledning WHERE  ProjektDelledning.SaneringsmetKode = NySaneringsData.SaneringsmetodeKode  AND ProjektDelledning.DelledningID =  NySaneringsData.DelledningsID))=False));


    If I try to remove the ProjektID I get validation rule violation instead. Any help would be much appreciated!

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,837
    you are trying to insert a new primary key that already exists

    If I try to remove the ProjektID I get validation rule violation instead
    because this is part of your primary key, it has to be completed, it cannot be null.

    Also to clarify, your sql code has an inner join, but the query view shows a left or right join - which is it?

    Also, if I have read your subquery correctly, you don't need it

    If it is supposed to be a left join, try

    Code:
    INSERT INTO ProjektDelledning ( ProjektID, DelledningID, SaneringsmetKode, DatoOprettet, DatoOpdateret )
    
    SELECT  ProjektDelledning.ProjektID, NySaneringsData.DelledningID,  NySaneringsData.SaneringsmetodeKode AS SaneringsmetKode,  Nz([ProjektDelledning].[DatoOprettet],Now()) AS DatoOprettet,  Nz([ProjektDelledning].[DatoOpdateret],Now()) AS DatoOpdateret
    
    FROM NySaneringsData LEFT JOIN ProjektDelledning ON NySaneringsData.DelledningsID = ProjektDelledning.DelledningID
    
    WHERE  ProjektDelledning.DelledningID IS NULL

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I'm trying to update the field SaneringmetKode in ProjektDelledning using DelledningsID as a join criteria.
    update the field: What do you mean by that? Are you trying to update fields in records that already exist, or are you trying to add new records to the table?

    If you want to add data to blank fields in records that already exist, you need to use an UPDATE query, not an APPEND.

    Can you clarify this, please?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Append query key violation
    By Paintballlovr in forum Queries
    Replies: 8
    Last Post: 10-11-2013, 12:50 PM
  2. Append Query Key Violation
    By oleBucky in forum Queries
    Replies: 6
    Last Post: 12-05-2012, 03:55 PM
  3. Key Violation - APPEND Query
    By Al77 in forum Access
    Replies: 5
    Last Post: 02-21-2012, 11:10 PM
  4. append, Key violation
    By klapheck in forum Queries
    Replies: 0
    Last Post: 09-17-2009, 11:50 AM
  5. unable to append... key violation... message box
    By Coolpapabell in forum Access
    Replies: 4
    Last Post: 08-31-2009, 02:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums