Results 1 to 5 of 5
  1. #1
    OprEowyn is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    3

    Parsing Middle of String

    I am pulling data from an external database and have linked the table to my Access database. In that table, there is a field "Description" that has several pieces of information that I need:
    AAAAAA-######-AA-AAAAAA
    Name-CustID-State-City

    The Name, CustID, and City all have variable lengths.

    I've parsed out the Name successfully in a query:
    Code:
    Left([Description],InStr([Description],"-")-1)
    Here is the code I'm using to parse the CustID in a query:
    Code:
    Mid([Description],InStr(1,[Description],"-")+1,InStr(InStr(1,[Description],"-")+1,[Description],"-")-1)
    This code yields:
    ######-AA-AA

    The string after the CustID is equal in length to the corresponding Name for that field.

    I can't see where I'm going wrong with my code - could you help?

    The current work-around I have is to then further parse the ######-AA-AA result I get, but then when I try to run a summary query and count records by CustID, I get the following error:


    ODBC--Call failed. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid length parameter passed to the SUBSTRING function. (#536)

    Thank you!

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Till some one comes along, just check out :
    Code:
    Mid([Description],InStr(1,[Description],"-") + 1,InStr(InStr(1,[Description],"-")+1,[Description],"-")-InStr(1,[Description],"-")-1)
    Thanks

  3. #3
    OprEowyn is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    3
    That solved the initial problem - my parsed string is now just the CustID. Thank you!

    When I run the summary query on the CustID, I'm still getting this error:
    ODBC--Call failed. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid length parameter passed to the SUBSTRING function. (#536)

    When I do a detail query on the same field, I don't get the error. Any suggestions? My ultimate goal is to have a count of billing items by CustID.

  4. #4
    OprEowyn is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2013
    Posts
    3
    I determined that the error was happening because my data was inconsistant. Sometimes it was AAAAAAAA-######-AA-AAAAAA, sometimes it was AAAAAAAA-######. Here is the final code I wrote that worked both to display the CustID and still worked in the summary query:
    Code:
    IIf([Description] Like "*-*-*",Mid([Description],InStr(1,[Description],"-")+1,InStr(InStr(1,[Description],"-")+1,[Description],"-")-InStr(1,[Description],"-")-1),IIf([Description] Like "*-*",Right([Description],InStr(1,[Description],"-")),"CHECK DATA"))
    Thank you, recyan, for your help!

  5. #5
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Glad you got things working.

    Thanks

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

Similar Threads

  1. Replies: 6
    Last Post: 02-13-2013, 04:54 AM
  2. Replies: 3
    Last Post: 05-08-2011, 12:55 PM
  3. Access front end for parsing xml string
    By raghu_nandan1 in forum Programming
    Replies: 0
    Last Post: 04-21-2011, 07:58 PM
  4. More than one middle name
    By vorstopzolder in forum Access
    Replies: 5
    Last Post: 02-10-2011, 01:09 AM
  5. how select middle characters on string ???
    By ayman.maher in forum Queries
    Replies: 1
    Last Post: 04-27-2010, 09:29 AM

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