Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    6

    Append Values from Query, While Incrementing Foreign Key Value

    Is there any way to run an append query that duplicates table values from some fields and increments others, for example:

    ID, SynIsDefault, SynID, Tag Value
    1, -1, 1, AAA
    2, -1, 1, BBB
    3, -1, 1, CCC

    ID is the primary key field and needs to increment. SynID is a grouping of the Tags that needs to increment by one for all tags. I would like to duplicate all the records and append the data to the table as such:
    4, -1, 2, AAA
    5, -1, 2, BBB
    6, -1, 2, CCC



    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Assume the ID is an autonumber field.

    Try something like:
    INSERT INTO tablename(SynIsDefault, SynID, [Tag Value]) FROM SELECT SynIsDefault, SynID + 1 As NewSynID, [Tag Value];
    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
    Join Date
    Mar 2012
    Posts
    6
    Thank you for your reply, unfortunately, the ID field does not autonumber.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Why not autonumber? Otherwise the code to sequentially number the records starting from the last number in table is complicated.

    Review this http://allenbrowne.com/ranking.html

    Are there multiple users?
    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. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  2. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  3. Incrementing Counter in Query
    By Rawb in forum Queries
    Replies: 9
    Last Post: 02-10-2011, 02:58 PM
  4. Query Table Values in Append Query
    By AKQTS in forum Queries
    Replies: 5
    Last Post: 11-12-2010, 03:58 PM
  5. Selecting foreign key values on data entry
    By hardya in forum Access
    Replies: 4
    Last Post: 02-11-2010, 11:56 AM

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