Results 1 to 13 of 13
  1. #1
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8

    Using InStr() inside Mid()

    Hello!!


    I have a field "Course" with data like:
    AAA 210
    AAA 210A
    AAAA 300
    AAAA 300A
    AA 250
    AA 250A

    I am doing:
    Mid([tablename]![Course],InStr([tablename]![Course]," ")+1,3) to get just 3 numbers after the space.

    This is not giving me those three numbers..Please help!!!

    Thanks in advance:-)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I deleted your duplicate thread. Please don't post the same question twice.

    What is that giving you?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8
    It is giving me different result for different row.
    AAA 210-->2
    AAA 210A-->2
    AAAA 300-->30
    AAAA 300A-->30
    AA 250-->blank
    AA 250A-->blank
    AAAAA 300-->300
    AAAAA 300X-->300

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Well, a hard-coded field works as expected in the Immediate window:

    ?Mid("AAAA 300A",InStr("AAAA 300A"," ")+1,3)
    300
    ?Mid("AA 300A",InStr("AA 300A"," ")+1,3)
    300

    Where are you using that exactly?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    By the way, are you sure there aren't multiple spaces in the data?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8
    I am using that in Expression builder in my select statement.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Did you check for multiple spaces? Your result could be the result of that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8
    well..looks like there are multiple spaces in the data..it is giving me 10 for all rows as length when i did Len(Course).

    Now, I guess it is getting complex!!

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Presuming the spaces are in the middle, that's your problem. I don't think Trim() will work on spaces in the middle of a string, so you're likely going to have to use Replace() to get rid of them. I don't do a lot of work with strings, so there may be an easier way. You can probably work around it with InStrRev(), which will find the last space instead of the first.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8
    well..I did: Mid(Right$([tablename]![Course],4),1,3) and it worked....

    Thanks a lot for pointing out that spaces!!

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Would that work since some have a letter at the end and some don't?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    urbi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    8
    yes it did..coz I believe it is arranged as: 5 char then 1 space then 3 digits and 1 char

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Data Seperation by InStr()
    By A S MANN in forum Queries
    Replies: 3
    Last Post: 10-20-2011, 03:47 AM
  2. InStr and Mid code creating type mismatch
    By sephiroth2906 in forum Programming
    Replies: 6
    Last Post: 09-15-2011, 10:59 AM
  3. SQL inside DLookup()
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 03-02-2011, 07:41 PM
  4. INSTR(), quick little syntax ?
    By markjkubicki in forum Forms
    Replies: 2
    Last Post: 11-15-2010, 02:46 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