Results 1 to 6 of 6
  1. #1
    Dave D is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    45

    Append Query to the same table changing only the primary key

    I'm not sure this is possible, but I would like to select a group of records from Table1 and insert the same records back into Table1 using the same data with the exception of changing the primary key.

    A sowId is the PK in Table1 and different SOWs sometimes use the same parts. So, instead of copying the records one-by-one (rs.AddNew /rs.Update), changing the sowId as I go, I would like to make the changes all at once with an Append Query.



    Is what I'm trying to do doable? If so, any suggestions as how to go about doing it?

    Thanks for any help you can provide.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Should be able to. Review http://www.w3schools.com/sql/sql_insert_into_select.asp

    What criteria would be used to select the records?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Dave D is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    45
    I'm thinking something like this:

    "INSERT INTO Table1 (sowId, partId, Qty)
    SELECT * FROM Table1 WHERE sowID=123"

    But, I can't figure out how to add the new sowId '456' in place of '123'.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Is sowID an autonumber field? The table will automatically assign the next available number to the new record. Do not include sowID in the sql.

    However, I tested with the * wildcard and it would not work.

    INSERT INTO Table1(partID, Qty) SELECT partID, Qty FROM Table1 WHERE sowID=123
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Dave D is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    45
    The sowId is passed from another form, it's not an auto-increment. Thanks for the heads up on the wildcard element. It looks like I get to loop my way though a recordset.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Correction, I did get the * wildcard to work if there was no unique ID field in the table. But since the fields have to be listed in the INTO clause, might as well list them in the VALUES part - which in this example is the SELECT subquery.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Changing primary keys
    By ksammie01 in forum Database Design
    Replies: 4
    Last Post: 02-07-2013, 07:56 PM
  2. Replies: 2
    Last Post: 03-23-2012, 09:20 AM
  3. primary key: changing of ramifs
    By stevepcne in forum Access
    Replies: 2
    Last Post: 11-19-2011, 06:29 PM
  4. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  5. Replies: 4
    Last Post: 03-04-2010, 06:26 AM

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