Results 1 to 6 of 6
  1. #1
    hashmio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    3

    Post Tricky Update Query based on containing records in another table

    Hi



    I have two tables:

    Table 1

    Name Origin
    Smith John E
    Blogs Tomasz B
    Ahmad Sarah
    Smith A
    Bill Ahmad F

    Table2

    Name Origin
    John English
    Tomasz Polish
    Ahmad Arab
    Smith English


    I would like to update the Table1.Origin with Table2.Origin where there is a match on the Table2.name

    I hope you can help

    Thanks

    Os

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Table1 should have the name parts in separate fields: FirstName, LastName

    You want to assign gender based on a person's first name? My name is June (female) but I had an uncle named June. Another uncle named Merideth. My mother (Carbrey) was named after her father. I have a niece Kelly and nephew Shawn.


    UPDATE Table1 SET Table1.Gender = Table2.Gender WHERE Left([Table1.Name], InStr([Table1.Name], " ")-1) = Table2.Name;

    or

    UPDATE Table1 SET Table1.Gender= DLookup("Gender", "Table2", "Table2.Name='" & Left([Table1.Name], InStr([Table1.Name], " ")-1) & "'")
    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
    hashmio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    3
    I updated the original post. I can't split the name as I have a very large pre-populated table where the complete name exists in 1 cell and sometimes has initials. Unless you can think of a way I can split it

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So the first name isn't even first in the string and this certainly complicates. Will the first name (or initial) always follow the lastname? Will there be any single word names, like Madonna, Cher, Fergie?

    What gender is Smith A?

    The names can and should be split into separate fields but would probably need VBA code to accomplish.

    Regardless of the approach, any output would require thorough review.
    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
    hashmio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    3
    Quote Originally Posted by June7 View Post
    So the first name isn't even first in the string and this certainly complicates. Will the first name (or initial) always follow the lastname? Will there be any single word names, like Madonna, Cher, Fergie?

    What gender is Smith A?

    The names can and should be split into separate fields but would probably need VBA code to accomplish.

    Regardless of the approach, any output would require thorough review.

    Please ignore the gender example as I actually wanted to update the names origin instead. The name will always have the last name first followed by a firstname or initial or both

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Consider this expression for extracting the first name.

    Left(Mid([Name],InStr([Name]," ")+1),InStr(Mid([Name],InStr([Name]," ")+1)," "))
    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.

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

Similar Threads

  1. Replies: 13
    Last Post: 11-27-2014, 10:18 AM
  2. Replies: 1
    Last Post: 11-23-2014, 02:20 PM
  3. Replies: 6
    Last Post: 11-22-2013, 07:59 PM
  4. Replies: 14
    Last Post: 12-06-2012, 11:25 AM
  5. Replies: 6
    Last Post: 05-10-2012, 08:20 PM

Tags for this Thread

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