Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Copy a single record from one table to another

    I've recently had an occasion to copy a record to another table:
    Code:
            CurrentDb.Execute "INSERT INTO tblAutoTrans SELECT * FROM tblRegister WHERE TRecID =" & Me.TRecID & ";"
    The code works fine but I'm surprised that the newly created record in table "tblAutoTrans" was not assigned a new primary autonumber value in its record ID field. Is that normal with such cases as with this copy operation?

    Would it be a more preferred approach to open a DOA Recordset of the target table and use AddNew to copy the desired fields?



    Bill

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    So did you get the AutonumberID from the tblRegister instead?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, the copy operation copied the record ID to the newly created copy in table "tblAutoTrans".

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Instead of using the SELECT.* use SELECT [Field2],[Field3].... leaving the autonumber field out and it will work as expected.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by GraeagleBill View Post
    Yes, the copy operation copied the record ID to the newly created copy in table "tblAutoTrans".
    I must admit I was not aware it would even do that, but rather complain?

    As mentioned omit that field then.

    However wouldn't you then lose any relationships? How would you tie that new record back to it's original source?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Vlad, that's all that was needed.
    Bill

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    However wouldn't you then lose any relationships?
    Normally one would have to consider any relationships pertaining to the record ID. In the current app, the user is simply in the midst of capturing selected records for purposes of creating register transaction templates devoid of any relationship concerns.

    Thanks,
    Bill

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

Similar Threads

  1. Replies: 1
    Last Post: 08-29-2018, 10:26 AM
  2. Replies: 3
    Last Post: 08-02-2015, 12:42 AM
  3. Replies: 4
    Last Post: 01-20-2015, 12:55 PM
  4. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  5. Copy record from one table to another
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 03-05-2013, 12:16 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