Results 1 to 11 of 11
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136

    Populating a table with values from another table


    I have a table in access where 2 of its columns need populating. It will be getting its values from another table.
    I am not sure how to do this?
    Last edited by mp3909; 03-19-2019 at 05:01 AM. Reason: make it more clearer

  2. #2
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    I need to populate two fields "LineId" and "BTMU_Relationship_Office" in this table:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	17 
Size:	44.5 KB 
ID:	37888

    from this table (which also has those 2 fields).

    Click image for larger version. 

Name:	Capture2.PNG 
Views:	17 
Size:	55.9 KB 
ID:	37889

    but where the field "OrgnsnCod" from the first table = "OrgnsnCod" from the second table
    AND ""TradeTyp" in the first table is equal to "CSPA"

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Try starting with a SELECT query that joins the 2 tables on the 2 pairs of fields. Then switch to UPDATE query and set the fields to update with which source fields.
    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.

  4. #4
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    I came up with this SQL code:

    Code:
    Sub runUpdateSQL()
    Dim sSQL As String
    sSQL = "UPDATE [Trade_Exposure_Report_All]"
    sSQL = sSQL & vbNewLine & "LEFT OUTER JOIN [tblCSPAmapping]"
    sSQL = sSQL & vbNewLine & "ON [Trade_Exposure_Report_All]![OrgnsnCod]=[tblCSPAmapping]![OrgnsnCod]"
    sSQL = sSQL & vbNewLine & "SET [Trade_Exposure_Report_All]![LineId]=[tblCSPAmapping]![LineId], [Trade_Exposure_Report_All]![BTMU_Relationship_Office]=[tblCSPAmapping]![BTMU_Relationship_Office]"
    sSQL = sSQL & vbNewLine & "WHERE [Trade_Exposure_Report_All]![TradeTyp]='CSPA'"
    sSQL = sSQL & vbNewLine & "AND [Trade_Exposure_Report_All]![LineId] Is Null"
    sSQL = sSQL & vbNewLine & "AND [Trade_Exposure_Report_All]![BTMU_Relationship_Office] is Null"
    CurrentDb.Execute sSQL
    End Sub
    and in the immediate window, my sql statement looks like this

    Code:
    UPDATE [Trade_Exposure_Report_All]
    LEFT OUTER JOIN [tblCSPAmapping]
    ON [Trade_Exposure_Report_All]![OrgnsnCod]=[tblCSPAmapping]![OrgnsnCod]
    SET [Trade_Exposure_Report_All]![LineId]=[tblCSPAmapping]![LineId], [Trade_Exposure_Report_All]![BTMU_Relationship_Office]=[tblCSPAmapping]![BTMU_Relationship_Office]
    WHERE [Trade_Exposure_Report_All]![TradeTyp]='CSPA'
    AND [Trade_Exposure_Report_All]![LineId] Is Null
    AND [Trade_Exposure_Report_All]![BTMU_Relationship_Office] is Null
    but I get error when I try to execute it, it says "JOIN expression not supported".
    I don't understand why?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Did you construct SQL with query builder?

    Not joining on both pairs of fields - compound join.
    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.

  6. #6
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    Yes, I did use Query Builder and just changed the join from Inner to Left as I want all the records from my left table.
    Still do not understand what's exactly wrong though?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  8. #8
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    sorry June7, but I have no clue what you are on about.
    I really do not have time to waste, wished someone just pointed straight to the answer.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    No clue about what? How to do compound join? How to attach file to post? I did point to an answer - compound join. Then I offered to review your db. I don't have time to waste either. I will now direct my attention to other threads.

    Good luck with your project.
    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.

  10. #10
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    By the look of it you don't need to do this as you can always pull that data from the source table, by simply querying with a join based on the orgnsncode, which appears to be the primary key.
    No need to duplicate the data or update your second table.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  11. #11
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    solved.
    Nothing about compound joins, instead it was syntactical error, replaced "!" with "."
    Last edited by mp3909; 03-20-2019 at 04:46 AM. Reason: clear

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

Similar Threads

  1. Vlookup
    By abrahamgluck in forum Access
    Replies: 6
    Last Post: 12-28-2017, 03:45 AM
  2. Replies: 9
    Last Post: 08-19-2015, 02:09 PM
  3. vlookup in a query
    By tomeratz in forum Queries
    Replies: 1
    Last Post: 07-13-2015, 02:21 AM
  4. Vlookup or similar for Access
    By ladyjoa in forum Access
    Replies: 4
    Last Post: 04-25-2014, 11:44 AM
  5. VLookup
    By chethan1333 in forum Access
    Replies: 1
    Last Post: 02-23-2013, 10:14 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