Results 1 to 6 of 6
  1. #1
    Whughes98 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Location
    Brunswick, GA
    Posts
    3

    Extracting text from a string

    I am trying to figure out the formula for how to extract a segment of text from a string with a fixed starting position but variable length, and variable starting position with fixed length. I feel like I should use a mid formula but I am not sure what formula to use for the variable length. Below is my example:



    400000 005-038 10 9999400 1
    400000 007-707 10 107412 1

    The first set of numbers I need to extract are the ones highlighted in yellow. The start position will be the same but the length will be different.

    The second set of numbers I need to extract are the ones highlighted in red. The start position is variable but the length will be fixed.

    I want these values in 2 separate fields in my table.

    Any help would be appreciated. I am trying to setup a template for individuals that don't know much about Excel and would be challenged by using text to columns.

    I am using MS Access 2013.

    Thanks,
    Wendy

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Don't think there is an answer for this one because the starting position can be different AND the variable length can be different from record to record. How are the users entering the data. In Excel? Why not split the "yellow" data and "red" data into separate columns?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,894
    If red data is always 3 characters, try:

    Red: Right([fieldname], 3)

    Yellow: Left([fieldname], Len([fieldname])-3)


    As already suggested by jwhite, would be better to enter into separate columns to begin with.
    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
    Whughes98 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Location
    Brunswick, GA
    Posts
    3
    That is what I am trying to do. Sorry that wasn't clear.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,894
    You are trying to fix existing data and future entries will be into separate fields? Good. Did post 3 resolve issue? Do you need to run an UPDATE query to fix data in Access table?
    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
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,404
    Couple of UDFs can do it.

    Code:
    Function GetRed(arg As String) As String
        Dim rslt As String
        rslt = Left(arg, Len(arg) - 2)
        GetRed = Right(rslt, 3)
    End Function
    
    
    Function getYellow(arg As String) As String
        Dim yStart As Long
        Dim yEnd As Variant
        yStart = 19
        yEnd = Len(arg) - 4 - yStart
        getYellow = Mid(arg, yStart, yEnd)
    End Function

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

Similar Threads

  1. Replies: 6
    Last Post: 05-29-2015, 10:21 AM
  2. Replies: 16
    Last Post: 11-03-2014, 02:38 PM
  3. Replies: 7
    Last Post: 06-06-2013, 10:32 AM
  4. Replies: 2
    Last Post: 11-02-2012, 01:20 PM
  5. Extracting text from XML data
    By rob4465 in forum Access
    Replies: 1
    Last Post: 03-18-2010, 06:41 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