Results 1 to 12 of 12
  1. #1
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36

    Return text after a string

    Within a text field there may be nulls, or text that contains the letters "LFU." I want a formula that searches for "LFU" in the string and then returns 6 characters starting in position 2 to the right of "LFU." If "LFU" cannot be found in the string I want to return "None."

    Everything I try either errors or doesn't give me the desired result. This was my best shot (excluding the "None" part) and it errors:

    Test: Right([Text],InStr([Text],"LFU")6)

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Try a comma , before the 6

    Post a few sample records , so readers can understand the data.

  3. #3
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    The comma before the 6 told resulted in the wrong number of arguments error.

    Some sample records could be null as I mentioned. Also:

    LFU 02/27/14

    Desired result for this record would be "02/27/14"

    01/17 - Terms should be Net 30

    Desired result for this record would be "None"

    Desired result for null, blank, or error would also be "None"



    ***correction, I said 6 characters, but it should be 8 to capture the "/"'s

  4. #4
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    I got this to work:

    Test:IIf(Left([Text],3)='LFU',Mid([Text],5,8),'None')

    However, the only flaw is that it requires "LFU" to be in position 1 of any string. I'd like it to be such that it would find LFU anywhere in the string and work the same way.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Consider:

    If InStr([Text], "LFU"), Trim(Replace([Text], "LFU", ""))), "None")
    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
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    That would work, but there are situations where additional text can be found after the date. I wouldn't want that text included. Only the 8 characters after "LFU "

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    I take it that this will be in a query, not vba.

    Reqd: IIf(InStr(Trim(Text), "LFU") = 0, "None", Mid(Trim(Text), InStr(Trim(Text), "LFU") + 4, 8))

  8. #8
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    Perfect, thanks!!

  9. #9
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Happy to help. Good luck with your project.

  10. #10
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    Another question on this. Obviously what I'm trying to return is a date value. Could I try something like this? (I did this and it didn't work but you see the idea):

    IIf(InStr(Trim([Text]),"LFU")=0,"None",Format(Mid(Trim([Text]),InStr(Trim([Text]),"LFU")+4,8)),"d/m/yy")

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    You have misplaced paren:

    IIf(InStr(Trim([Text]),"LFU")=0,"None",Format(Mid(Trim([Text]),InStr(Trim([Text]),"LFU")+3,8),"d/m/yy"))
    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.

  12. #12
    Madmartigan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2013
    Posts
    36
    Fantastic - thank you!

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

Similar Threads

  1. Replies: 6
    Last Post: 01-21-2014, 06:39 PM
  2. Replies: 3
    Last Post: 12-22-2012, 05:33 PM
  3. Replies: 3
    Last Post: 11-22-2012, 08:01 PM
  4. check and return specified text
    By nosiss in forum Queries
    Replies: 7
    Last Post: 05-17-2011, 02:29 PM
  5. Replies: 1
    Last Post: 11-05-2010, 04:31 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