Results 1 to 8 of 8
  1. #1
    murleyj is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    16

    Extract text from a field

    I have a field named [Descrip]



    There are thousands of records in the table in which it resides...table name [Routing]

    Using Access Query design, i need to search for records in the [Descrip] field that begin specifically with the word "PROG " (minus the quotation marks) and then extract every bit of text from the first space to the first carriage return.

    Is this possible? The DATA TYPE of this field is identified as "Long Text".

    What do I need to put in the query to return just the text I need?


    Thank you!

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Quote Originally Posted by murleyj View Post
    i need to search for records in the [Descrip] field that begin specifically with the word "PROG " (minus the quotation marks)
    Use the query criteria "PROG *" (Need quotatrion marks) will search all the records begin with the word "PROG ".

    Quote Originally Posted by murleyj View Post
    extract every bit of text from the first space to the first carriage return.
    Use the Mid function and search for Chr(13) and/or Chr(10) will find the first carriage return and line feed.

    Need help on the Mid function. Look here http://www.techonthenet.com/access/f...string/mid.php

  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,972
    Will also need InStr function. http://www.techonthenet.com/access/functions/index.php

    Mid([Descrip], 6, InStr(Chr(13)) - 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.

  4. #4
    murleyj is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    16
    Thanks, guys. But I am not sure how to put all of this together in the Query builder in Access. See the below picture for what I currently have:

    Click image for larger version. 

Name:	example.jpg 
Views:	9 
Size:	132.4 KB 
ID:	20218

  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,972
    Create another field with the example expression. Put the expression in a cell on the Field row of the grid.
    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
    murleyj is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    16
    Thanks again, but I don't believe I follow....this is what I am getting:


    Click image for larger version. 

Name:	example.jpg 
Views:	8 
Size:	137.5 KB 
ID:	20221

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Sorry for my typo:

    Mid([Descrip], 6, InStr([Descrip], Chr(13)) - 6)

    Also have to subtract 6, not 1. I tested in VBA immediate window and this worked.

    Consistency of data structure is critical in string manipulation. Also, the expression will error on an empty string and return Null if field is Null.

    Carefully study the referenced links. With a little practice you will gain a better understanding of these functions and recognize these errors.
    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.

  8. #8
    murleyj is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    16
    Awesome. Thank you very much. That worked great!

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

Similar Threads

  1. Extract Text
    By mchadwick in forum Access
    Replies: 1
    Last Post: 11-10-2014, 02:25 PM
  2. Extract text from a certain word to the right
    By webisti in forum Queries
    Replies: 4
    Last Post: 10-23-2014, 12:18 PM
  3. Replies: 1
    Last Post: 05-24-2013, 02:44 AM
  4. Extract text from middle of a field
    By AccessNubie in forum Access
    Replies: 3
    Last Post: 11-02-2009, 01:13 PM
  5. Extract numbers from text string strored in a field.
    By khabdullah in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 06:55 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