Results 1 to 5 of 5
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Split City And State


    I have a table that has city, state zip in one field so the data reads like this
    Code:
    City, State Zip
    or a more literal example is
    Code:
    Atlanta, GA 00000
    How can I split the State (GA) out of that field and into it's own column in the query?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    oops, seems no available in a query
    You could use Instr() twice?, once to find first space (or the comma) and once to find the next space. along with a mid() ?

    Alternative create your own Split?

    Code:
    Public Function MySplit(strToSplit As String, iIndex As Integer)
    
    MySplit = Split(strToSplit)(iIndex)
    
    End Function
    Code:
    ? mysplit("Atlanta, GA 00000",1)
    GA
    
    HTH
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    City: Left(fieldname, InStr(fieldname, ",") - 1)

    State: Mid(fieldname, InStr(fieldname, ",") + 2, 2)

    Zip: Mid(fieldname, InStrRev(fieldname, " ") + 1)
    Last edited by June7; 06-08-2021 at 02:15 PM.
    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
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Alternative create your own Split?
    ...and call it from a query (if need be).
    Or Instr +2 to find 1st character of state, then Mid(of that point,2)?
    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. API to find City,State given a zip code
    By GraeagleBill in forum Programming
    Replies: 6
    Last Post: 03-18-2019, 12:11 PM
  2. Create address, city, state, zip columns
    By tmcrouse in forum Queries
    Replies: 5
    Last Post: 06-08-2015, 12:51 PM
  3. Replies: 2
    Last Post: 03-18-2014, 10:15 AM
  4. Texas City,State,Zip and Area Code
    By burrina in forum Sample Databases
    Replies: 0
    Last Post: 11-12-2012, 10:35 PM
  5. City, State Zip lookup
    By garywmcp in forum Access
    Replies: 1
    Last Post: 04-24-2011, 06:15 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