Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23

    matching string of text and extracting into new field

    Hi, I have a field called "contents" in two different tables that fetch the body of email messages. One table is called test1 the other test2. I need to write a query that will match a string of text that shows up in the middle of both of the fields that look like this:

    [test1].contents looks like
    File List:
    13495234978423usa.zip

    Login


    ------------And---------

    [test2].contents looks like:

    File List:
    13495234978423usa.zip
    Total(no extra space)

    I need help extracting just the “13495234978423usa.zip” string of text to put into a new field called extracted_text in each of their respective tables.

    Any takers?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Are you saying the field [contents] contains the actual string "Field List:" followed by a CrLf in every record?

    The part you want will always by 21 characters?
    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
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    The contents field will always contain "File List:" followed by a CrLf in every record. The filename i'm trying to extract isn't always 21 characters long though.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    That does complicate.

    I forgot to ask if "File List:" is always the beginning and a CrLf follows the file name? Is it always .zip? Is that the only dot in the string?

    x represents the field:

    Mid(x, InStr(x,Chr(10))+1, InStr(x,".") - 9)

    Consistency is critical in string manipulation.
    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
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    "File List:" is always in the middle of the contents and is always followed by CrLf. It can either be .zip, .rar, .doc,.pdf.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Okay, is that the first CrLf? Is that the only dot in the string? Is that the only colon? All extensions are 3 characters?

    Mid(x, InStr(x,":")+3, InStrRev(x,Chr(13)) - InStr(x,":")-3)

    or

    Mid(x, InStr(x,Chr(10))+1, InStrRev(x,Chr(13)) - InStr(x,Chr(10))-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.

  7. #7
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    all extensions are 3 characters but there are several colons and several CfLf before this line.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Mid(x, InStr(x,"File List:")+13, InStrRev(x,Chr(13)) - InStr(x,"File List:")-13)
    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.

  9. #9
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    that worked. could you please help me using it with a update query?

  10. #10
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    Nevermind. thanks so much!!!!

  11. #11
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    So, i didn't realize i didn't have the field expanded. Your solution starts with the file name but it doesn't end at the file extension. It extracted all the message after the file name. Any suggestions?

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    It works for me with the example data provided.

    As I said, consistency in structure is critical to text manipulation. I can only work with info provided.
    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.

  13. #13
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    better yet, can't i run another update query that will remove everything after the first CfLf

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Yes. But it would be nice to do all in one action. Need better understanding of data structure.

    Is this a one-time event or will you need to do this periodically?
    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.

  15. #15
    bchi99 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    23
    It's just a one time event.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 06-06-2013, 10:32 AM
  2. Replies: 2
    Last Post: 11-02-2012, 01:20 PM
  3. Replies: 1
    Last Post: 08-11-2011, 11:33 AM
  4. Extracting text from a field
    By bwash70 in forum Access
    Replies: 4
    Last Post: 11-24-2010, 08:10 PM
  5. String Matching
    By tuna in forum Programming
    Replies: 1
    Last Post: 05-16-2010, 12:22 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