Results 1 to 3 of 3
  1. #1
    yosko1 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2018
    Posts
    1

    Post Update text in one column based on first intance of data in two other columns

    I have two tables, #1 has a spending estimate column and table #2 has columns with Vname, Color, Part and Spending estimate. Need to update the #2 table with the information from Table #1 but only the first time in a row that Vname and Color are the same.

    TbL #1
    Name Color SpendEst
    Dart Yellow 2500.00
    Dart Red 3000.00
    Arrow White 2000.00
    Arrow Blue 1000.00



    Tbl #2
    Name Color Part SpendEst
    Dart Yellow Door 2500.00
    Dart Yellow Handle
    Dart Yellow Rest
    Dart Red Handle 3000.00
    Dart Red Rest
    Dart Red Mirror
    Arrow White Door 2000.00


    Arrow White Rest
    Arrow White Mirror
    Need to update the SpendEst in Tbl#2 with the SpendEst information in Tbl #1, but only the first time that the Name and Color in Tbl#2 match with the Name and Color in Tbl#1. The following rows for SpendEst column should remain blank

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    What exactly determines which record is 'first'? Access records do not have inherent order (a table is not a spreadsheet). Must use data as criteria to select and order records.
    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
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    just in case those are real field names, Name is a reserved word and should not be used for an object name.

    I agree with the ordering sentiment. I know you can get something that resembles the expressed goal using a Select query, but if it uses aggregate functions (such as First) you can't use it in an update query, so I don't see that working. You'd probably have to create a table with it first:
    Code:
    SELECT [table2].[Name] & " " & [table2].[color] AS NameColor, Min(Table2.Part) AS MinOfPart, Table1.SpendEst
    FROM Table1 INNER JOIN Table2 ON (Table1.Color = Table2.Color) AND (Table1.Name = Table2.Name)
    GROUP BY [table2].[Name] & " " & [table2].[color], Table1.SpendEst, Table2.Name, Table2.Color;
    Name Color MinOfPart SpendEst
    Arrow White Door 2000
    Dart Red Handle 3000
    Dart Yellow Door 2500

    This might appear to work, but as June7 says, there's no guarantee of the order of a set of table records. You'd have to use a select query with an Order By clause or have a table field expressly for ordering to be safe.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 4
    Last Post: 11-29-2017, 10:01 AM
  2. Replies: 5
    Last Post: 04-26-2016, 05:30 AM
  3. Replies: 2
    Last Post: 03-10-2015, 11:47 AM
  4. Replies: 1
    Last Post: 11-12-2013, 02:19 AM
  5. Replies: 3
    Last Post: 08-08-2011, 11:02 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