Results 1 to 3 of 3
  1. #1
    Bluejack17 is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2022
    Posts
    1

    Replace all the records in a column with a new value given in another table

    Hi There


    How can i replace all city names in the cities table with the ID for that city from the cityID table.
    Thank You In Advance.
    Click image for larger version. 

Name:	Access-Table2_small.png 
Views:	15 
Size:	40.1 KB 
ID:	47482Click image for larger version. 

Name:	Access-Table1_Small.png 
Views:	15 
Size:	61.5 KB 
ID:	47483

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps something like:
    Code:
    UPDATE Cities INNER JOIN [City Code] ON Cities.City = [City Code].City SET Cities.City = [ID];
    and then change the data type of [City Names] to something numeric rather than text.

    Alternatively, you could use a query to retrieve the [ID] from matching Cities. Something like:
    Code:
    SELECT [City Code].City, [City Code].ID
    FROM Cities INNER JOIN [City Code] ON Cities.City = [City Code].City;
    BACK UP YOUR DB BEFORE TRYING
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    IMO you should add a numeric CityID field first, populate that, then remove the cities text field. Otherwise, you'll be trying to join a text to a numeric field.
    Bob, maybe you tried that sql for this situation, so I'd be full of it if I said that I suspect the inner join (both field records are equal) won't work when one field is a number and the other is text. Also, in 2nd pic ID1 field (that's a bad name for any field) looks like an autonumber and you can't update that field, thus adding the number field first would be required.
    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: 3
    Last Post: 05-17-2020, 09:23 AM
  2. Replies: 13
    Last Post: 03-22-2019, 04:09 PM
  3. Filter records and update table column.
    By Thompyt in forum Queries
    Replies: 5
    Last Post: 11-07-2016, 01:34 PM
  4. Replies: 5
    Last Post: 04-18-2012, 10:54 AM
  5. Replies: 3
    Last Post: 11-24-2010, 06:33 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