Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2021
    Posts
    14

    Extracting a Sub String from a field

    Hi !!

    One of the fields in my Table is DETAILS.

    I need to build a query in which The DETAILS field should only reflect characters starting from 1 upto the first blank space it encounters.

    eg.
    Details field is "DAWAHI AL NABA TRADING-123" ... it should extract and display "DAWAHI"
    Details field is "KHIMJI RAMDAS - 3050365871" ... it should extract and display "KHIMJI"
    Details field is "INBB22060028 - WATERFRONT" ... it should extract and display "INBB22060028"



    Any help would be appreciated.
    Thx!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    Try
    Left([Details],Instr(1,[Details]," ")-1)

    EDIT: code correction; added -1. Could use Trim function if the -1 is omitted.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jul 2021
    Posts
    14
    Quote Originally Posted by Micron View Post
    Try
    Left([Details],Instr(1,[Details]," ")-1)

    EDIT: code correction; added -1. Could use Trim function if the -1 is omitted.

    Thx Micron .... It works except in the foll condition where the DETAILS field doesn't contain any blank spaces at all

    eg
    SAVILLS-4144
    EXTRA28960

    In the above 2 cases it throws up a #ERROR

    Any workaround?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    So test for the space?
    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

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    It would help if you could state what ALL of the possible scenarios might be and the desired results for each.
    There is always a work around, but I have no idea what you want as results when the data is
    SAVILLS-4144
    EXTRA28960

    You just want
    SAVILLS-4144
    EXTRA28960 ?

    EDIT - your post is in Reports forum. I'm assuming the solution is desired for a calculated query field. Maybe
    IIF(Is Null([Details]),[Details],Left([Details],Instr(1,[Details]," ")-1))
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    perhaps

    iif(instr(nz([Details])," ")=0,[Details],Left(nz([Details],""),Instr(nz([Details],"")," ")-1))

    Although the nz is only required for the first comparison, the whole iif statement will be evaluated so can fail on subsequent evaluations

  7. #7
    Join Date
    Jul 2021
    Posts
    14
    Thank you so much everyone for your Inputs and guidance. With all your help I was finally able to get it to work.

    Micron: My apologies on 2 counts ...
    1) I wasn't clear as to what I wanted in the workaround ... and
    2) For posting in the wrong forum ... This should've been posted in the QUERIES forum.

    Once again ... I can't thank you'll enough.

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    For the benefit of those who might look at this thread in trying to solve a similar problem, it's helpful if you post your solution.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Join Date
    Jul 2021
    Posts
    14
    Quote Originally Posted by Micron View Post
    For the benefit of those who might look at this thread in trying to solve a similar problem, it's helpful if you post your solution.
    I used a combination of yours and C J London's solution, but the client requested me to revert to the previous solution which threw up the #ERROR so they could get an indication of which data was incorrectly entered and rectify those entries.

    Once again, thank you folks.

  10. #10
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    You're welcome. We're glad to be able to help.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    Happy to help
    which data was incorrectly entered
    better to tackle this at the point of entry - whether manual input or data import

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

Similar Threads

  1. EXtracting substring from a string
    By pderwael in forum Access
    Replies: 4
    Last Post: 12-28-2021, 04:23 AM
  2. extracting from middle of string
    By sem1604 in forum Queries
    Replies: 3
    Last Post: 05-08-2018, 04:52 AM
  3. Extracting text from a string
    By Whughes98 in forum Queries
    Replies: 5
    Last Post: 04-17-2017, 11:18 AM
  4. Replies: 16
    Last Post: 11-03-2014, 02:38 PM
  5. Replies: 2
    Last Post: 11-02-2012, 01:20 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