Results 1 to 7 of 7
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Append Query to only append new records, How to do this?

    Hi all - Good morning

    I am trying to do an append query to only append new records (QryAttached)
    I have watched several video and read a whole bunch of references yet i cannot get this to append only new records.


    If I do it the way some vidoes show me i get an error message.
    With that said, left table is the info I want to append to the right table. I added a # field in right table (TableID) as wouldnt work with the actual auto id.
    The existing query actually works but creates duplicates if run over and over...
    Any help with this would be so kind. I have three tables, (Purchase, Payment, and Deposit) that I need to append into this same table so i can create reports from one table
    with deposits and withdrawals and such....In case you are curious

    Design View

    Click image for larger version. 

Name:	Qry1.jpg 
Views:	15 
Size:	148.9 KB 
ID:	47223

    Sql
    Code:
    INSERT INTO tblCatagoryDetail ( [TableID], AccountID, CatagoryTypeID, CatagoryID, SubCatagoryID, Withdrawal, Travel, SubCatagoryName, TransactionID, TransDate )
    SELECT DISTINCTROW tblCatagoryDetailPurchase.CatagoryDetailPurchaseID, tblCatagoryDetailPurchase.AccountID, tblCatagoryDetailPurchase.CatagoryTypeID, tblCatagoryDetailPurchase.CatagoryID, tblCatagoryDetailPurchase.SubCatagoryID, tblCatagoryDetailPurchase.Cost, tblCatagoryDetailPurchase.Travel, tblCatagoryDetailPurchase.SubCatagoryName, tblCatagoryDetailPurchase.TransactionID, tblCatagoryDetailPurchase.TransDate
    FROM tblCatagoryDetailPurchase LEFT JOIN tblCatagoryDetail ON tblCatagoryDetailPurchase.[CatagoryDetailPurchaseID] = tblCatagoryDetail.TableID;
    Thanks
    Dave

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,815
    One way is to create a select query that gives you only the records you want, then use that as a "table" in your append.
    Another is to create a unique index on the table field(s) and run your query. You get a warning, not an error, about records that could not be appended. You can trap this in vba code or just ignore it if you're the only user (you know it basically means nothing of importance).

    A potential issue is that your details table should have a field that holds the pk (primary key) from the left table (field in right table must be long integer number type), so ID 8 (for example) in left table is foreign key (fk, value = 8) that is stored in right table as many times as there are related records in right table. Maybe that's what "TableID" is?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736
    Dave,

    Here's a sample that works. You could work from/with the structure.

    Code:
    INSERT INTO AnasttinNew ( Product, InPlaceYearStart, InPlaceYearEnd, YearOfData )
    SELECT Anasttin.Product, Anasttin.InPlaceYearStart, Anasttin.InPlaceYearEnd, Anasttin.YearOfData
    FROM Anasttin LEFT JOIN AnasttinNew ON Anasttin.ID = AnasttinNew.ID
    WHERE (((AnasttinNew.ID) Is Null));
    where:
    -table to get the INSERTed records is AnasttinNew
    -table to supply the "new" records is Anasttin
    -the select list is the fields to be inserted
    -(AnasttinNew.ID) Is Null means these records are not in the AnasttinNEW
    --main point is the Left Join

    Good luck,

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    Thanks for input, yes, the TableID is the PK field for the left table and is a nunber, long int
    The qry above does show me the records, just wont put in only new records. Looks like Orange has
    A solution I will tryout,
    Thanks
    Dave

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Thanks Orange,
    I will give this a shot. I beleive I can sort through it and make it work for me.
    I eventlally will put this in the after insert on form so it works every time i add something new.\

    Thanks again
    Dave

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    That worked very well orange,
    Thanks
    Will mark solved.
    Thanks
    Dave

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,736
    Dave
    Glad it worked for you. Happy to help.


    In my example one table was a copy of the other, the original had a few more records added.
    So, I could use the autonumber field compare to identify the records that should be appended.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-03-2021, 08:32 AM
  2. Replies: 19
    Last Post: 10-03-2017, 09:10 AM
  3. Access can't append all the records in the append query
    By fluffyvampirekitten in forum Access
    Replies: 2
    Last Post: 08-27-2015, 01:53 AM
  4. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  5. Replies: 7
    Last Post: 07-21-2011, 01:01 PM

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