Results 1 to 7 of 7
  1. #1
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49

    Shortcut to update values from all Field names from one table to another

    With help, the Upsert code below now works.


    The structure of both tables is exactly the same.
    We plan on using the upsert code for some tables that will have over one hundred compounds (PFOS, PFOA, ...)
    Rather than go line by line, is there a way to set the equivalencies for each individual field?

    Current Code that would end up having lots of lines:

    Code:
    UPDATE tblTemp 
    LEFT JOIN dbo_tbl537 ON tblTemp.LabID = dbo_tbl537.[LabID] 
    SET 
    dbo_tbl537.LabID = tblTemp.[LabID], 
    dbo_tbl537.[Date] = tblTemp.Date, 
    dbo_tbl537.PFOS = tblTemp.PFOS,
    dbo_tbl537.PFOA = tblTemp.PFOA,
    dbo_tbl537.PFHxS = tblTemp.PFHxS,
    dbo_tbl537.PFNA = tblTemp.PFNA;
    What I want to do that doesn't work:

    Code:
    UPDATE tblTemp 
    LEFT JOIN dbo_tbl537 ON tblTemp.LabID = dbo_tbl537.[LabID] 
    SET 
    dbo_tbl537.* = tblTemp.* ;

    Thanks for looking.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Must do the first syntax.

    Alternative is to redesign db structure. Or complex VBA manipulating recordset.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Since the names are the same use the query qbe to drag all the field down - takes a second or so

    edit: I think��

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Unfortunately, cannot drag into UPDATE TO cell.
    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
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49
    I've been away a couple of weeks. Sorry for not getting back sooner.

    I will write a VB macro in Excel that generates the text for the query. That way we don't have to type out the entire query by hand.

  6. #6
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Why Excel? You can write a function in Access itself to generate the SQL. Just loop through all fieldnames to generate the SQL string.

  7. #7
    chromachem is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2016
    Posts
    49
    Will do. I gotta wean myself off excel . I would have used excel because I already know how to do it.

    TY!

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

Similar Threads

  1. Replies: 5
    Last Post: 04-01-2019, 09:54 PM
  2. Replies: 7
    Last Post: 03-21-2018, 04:58 AM
  3. How Access update two table without field names?
    By llgtjb001 in forum Queries
    Replies: 16
    Last Post: 09-10-2015, 03:15 PM
  4. Update values from field in another table
    By gedwards913 in forum Import/Export Data
    Replies: 1
    Last Post: 03-10-2015, 11:42 AM
  5. Replies: 0
    Last Post: 09-03-2014, 02:37 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