• Deleting Characters from Numeric Strings (97)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Deleting Characters from Numeric Strings (97)

    Author
    Topic
    #374438

    Hi, in a query I am trying to write an expression which deletes the last two digits from a variable length numeric string – I know there’s a function out there somewhere, but can find it……….. Can anyone help??? Thanks!

    Viewing 0 reply threads
    Author
    Replies
    • #605654

      Well if is a true string then you can do this:

      strNumber = left$(strNumber, len(strNumber)-2)

      • #605658

        Hi thanks very much for help. I’m sorry to be obtuse…. its that Friday afternoon feeling….(well, daily feeling in my case!) What I am trying to do is this – I have an inventory id number field which may vary from 3 to however many in length. Taking away the last two digits of this ID gives me another code which I need to use as a link to another table. I have been trying Left(([Inventory_Id],4)) but obviously this doesn’t allow for the variable length of the string. Can you tell me how I would fit the Len function into this scenario?

        • #605664

          Based on the fact that you [] around the Field name, it looks like you are doing this in a Query, correct?

          If so, you will need to use this:

          TrimmedInvNo: Left$([Inventory_Id],Len([Inventory_Id])-2)

          If you are doing it in VBA code then you will need to use this:

          lngTrimmedID = cLng(left$(cStr([Inventory_ID]), len(cStr([Inventory_ID])) -2))

          The cStr converts a Numeric value to a string, so you can use string manipulation on it.
          The cLng converts the final trimmed string back to a Long Integer.

      • #605660

        Hello again – having slapped myself around head very hard indeed, now see what you were trying to tell me! thanks very much worked a treat!

        Marion

    Viewing 0 reply threads
    Reply To: Reply #605658 in Deleting Characters from Numeric Strings (97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel