Results 1 to 4 of 4
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Need to Append only the last record from 1 table to another

    Hello all,

    I am trying to append a record from 1 table to another and I am having issues, it appends all of the records currently.

    This is the current SQL statement,

    INSERT INTO [Inventory Transactions] ( DHRID, ProductID, [DhrLot #], TransactionDate, TransactionDescription, UnitsReceived, SerialNum )


    SELECT DISTINCTROW [Work Orders].DHRID, [Work Orders].PartID, [Work Orders].DHRNumber, [Work Orders].StartDate, [Work Orders].DHRDescription, [Work Orders].Qty, [Work Orders].SerialNum
    FROM [Work Orders]

    This does a fine job of appending all of the records but I only need the last record.

    Thanks

    Dave

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You need an identifier for the last record.
    do you have an autonumber? Then it will be the largest #.
    Make Q1 to get the largest #:
    select ID, Max(ID) from table.

    then Q2 add it with an append query using Q1:
    insert into table2 (fld1, fld2) select ID, name from table1 ,Q1 where table1.ID=Q1.ID

  3. #3
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    ranman256,

    Can I do that in the query design? I have the last ID but don't understand how to incorporate that into the original within the design mode,

    Correction ; I got it to work fine

  4. #4
    Join Date
    Apr 2017
    Posts
    1,792
    The basic query is (Assumed KeyField is field/combination of fields, which is growing for later entries)
    Code:
    INSERT INTO SourceTable
    SELECT TOP 1 * FROM TargetTable
    ORDER BY KeyField Desc

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

Similar Threads

  1. Replies: 2
    Last Post: 09-14-2017, 05:09 PM
  2. Replies: 2
    Last Post: 04-21-2017, 01:15 PM
  3. Do you want to append the record in the table?
    By sukhjinder in forum Queries
    Replies: 1
    Last Post: 09-10-2016, 06:17 AM
  4. Replies: 4
    Last Post: 01-20-2015, 12:55 PM
  5. Find First record and append to another table
    By craig1988 in forum Modules
    Replies: 2
    Last Post: 01-15-2015, 09:30 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