Results 1 to 5 of 5
  1. #1
    Vodi's Avatar
    Vodi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    10

    Add stock numbers from one table to another if the stock number doesn't already exist


    Good day,

    I have a table, tbl_RYG, that gets imported monthly. The indexed field in this table is a stock number (PNSN). I have another table, tbl_Tracker_Notes, that I would like to contain all of the stock numbers that have ever been imported. It contains different fields that data is input into through a form.

    Is there a qry, code, or method that will look at the stock numbers from the import (tbl_RYG) and compare them to the tbl_Tracker_Notes, and will add new ones from tbl_RYG into tbl_Tracker_Notes?

    Your time and assistance are much appreciated.

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    The following is an example how to do this:

    INSERT INTO TableB (Item Number)
    SELECT TableA.Item Number
    FROM TableA
    WHERE TableA.ItemNumber NOT IN (SELECT ItemNumber FROM TableB);

    Modify to suit your table/field names and columns.

  3. #3
    Vodi's Avatar
    Vodi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    10
    Thanks, jwhite. Where would I place that code?

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    use a left join to identify missing records - something like

    Code:
    INSERT INTO tblTrackerNotes (fld1, fld2)
    SELECT tblRYG.fld1, tblRYG.fld2 
    FROM tblRYG LEFT JOIN tblTrackerNotes ON tblRYG.ID=tblTrackerNotes.ID
    WHERE tblTrackerNotes.ID is Null
    And given your last post - open a new query, go to the sql window and paste the code, then correct names to your actual names

  5. #5
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    You can create a New Query, modify it as desired and save it, perhaps named qryTrackImportedStockNumbers

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

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2014, 04:51 AM
  2. Create a Stock of documents numbers
    By CFGOYANES in forum Access
    Replies: 2
    Last Post: 02-10-2014, 01:44 PM
  3. Replies: 1
    Last Post: 05-13-2013, 05:01 AM
  4. Replies: 1
    Last Post: 07-11-2012, 01:42 PM
  5. Replies: 3
    Last Post: 03-14-2012, 12:33 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