Results 1 to 4 of 4
  1. #1
    LordJonSnow is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    3

    Query: Convert String & Return Partial - getting #Error sometimes

    Howdy from the n00b!



    I am trying to get a query to pull data from a field in one table, then convert to a number, and then split the data into two fields in another table. The first part works great, the second part, not as much. I know why it's not working, but can't sort out how to handle for the occasional #Error that's returned.

    So the data in Table 1 looks like this typically: "P123456/001" or "P123456 A/001", and I want the first part ("P123456") in one field as text, and the second part ("001") in the second field as numeric/double. That's fine, got that down, and it's working great!

    The problem is happening when occasionally there is an entry in Table 1 that looks like this "0012345/" (still a text field); again, first part is ok ("0012345"), but the second part returns the #Error that I'm seeing.

    So I know that the problem occurs because there is nothing after the "/" in the source field. Can anyone help determine how to compensate for this? I've tried IsNull, IsError, and IsNumeric, all with the same result.

    Here is my formula:
    IIf(IsNull[ShippingSchedule]![Supplier Reference],Null,CDbl((Mid([ShippingSchedule]![Supplier Reference],InStr([ShippingSchedule]![Supplier Reference],"/")+1))))

    Here is how I tried with IsNull, IsError, and IsNumeric:
    IIf(IsNull([ShippingSchedule]![Supplier Reference]),Null,IIf(IsNumeric(CDbl(Mid([ShippingSchedule]![Supplier Reference],InStr([ShippingSchedule]![Supplier Reference],"/")+1))),CDbl(Mid([ShippingSchedule]![Supplier Reference],InStr([ShippingSchedule]![Supplier Reference],"/")+1)),0))


    Thanks in advance to anyone who can help!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Make a query that creates these 2 fields for you.
    [myCode], left([myCode],Instr([[myCode],"/")-1) as part1, mid(myCode],Instr([[myCode],"/")+1) as part2

    This will break up the fields and let you see them AND possibly find errors.
    THEN perform your actions off this query, instead of making extremely complicated IF statements.

  3. #3
    LordJonSnow is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    3
    Yep... did a plain select query (thanks for the tip).

    Using simple formulas, as you suggested, returned no #Error.

    So I took the next step and added back just the conversion to Double on the second part, and the #Error came back.

    Formulas:

    Left([ShippingSchedule]![Supplier Reference],InStr([ShippingSchedule]![Supplier Reference],"/")-1)

    CDbl(Mid([ShippingSchedule]![Supplier Reference],InStr([ShippingSchedule]![Supplier Reference],"/")+1))

    Only on the second part.

    So normal numbers convert from/to this:

    P123456/001 to (two fields) P123456 | 1

    And the abnormal ones convert from/to this:

    0012345/ to (two fields) 0012345 | #Error

    I just want that to be Null where it says #Error


  4. #4
    LordJonSnow is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    3
    No other ideas??



    EDIT:
    Very strange. Tried it again this morning, and it worked perfectly!
    IIf(IsNull([WERPShippingSchedule]![Supplier Reference]),Null,CDbl(Mid([WERPShippingSchedule]![Supplier Reference],InStr([WERPShippingSchedule]![Supplier Reference],"/")+1)))



    Thanks again for the reminder to take it basic to find the error, ranman!
    Last edited by LordJonSnow; 06-11-2014 at 08:58 AM. Reason: Update

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

Similar Threads

  1. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  2. Return results based on a partial search
    By TimMoffy in forum Queries
    Replies: 2
    Last Post: 07-27-2012, 11:09 AM
  3. Query to convert String to Date??
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 06-04-2012, 04:48 PM
  4. Replies: 1
    Last Post: 03-22-2010, 03:37 PM
  5. Convert string to date
    By ~SwAmPdOnKeY~ in forum Queries
    Replies: 4
    Last Post: 09-11-2008, 07:19 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