• How to delete 1 character frm a string (Office pro 97 )

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How to delete 1 character frm a string (Office pro 97 )

    Author
    Topic
    #364937

    What code will delete the first character of a string of alphabetical characters which may be 1-50 characters in length? The code I am using now works fine unless the first character is the only character and then it tells me that the field can’t be blank. Which it can. It seems to mean that the string it is returning can’t be blank. Isn’t there a simple way to say edit this field and delete first character?

    this works unless there is no 2nd character for it to return
    Dim KRNT As String
    KRNT = [C4R]
    MKRNT = Mid$(C4R, 2, 50)
    C4R = MKRNT

    I tried Right$ and Left$ But they returned the 1st or last characters. Right$ would work if the string was always the same length but it varies and I can’t figure out how to make it deal with that.

    TX

    Viewing 2 reply threads
    Author
    Replies
    • #561808

      Why are you passing it the third argument to the Mid$ function if you don’t know for sure what the length will be? You should be able to do this:

      MKRNT = Mid$(C4R,2)

      to get everything from the 2nd character on.

      You’ll need to test the len of the string first to see if it’s greater than 1. If it is, use the Mid$ function. Otherwise, just set the variable to a null string, if that’s what you wanted to do.

      • #561868

        Tx Charlotte

        First of all my book(s) say it must have the third argument. I tried leaving it blank but I think I left the comma in. It didn’t like that. I will try it without the comma today.

        • #561879

          If you put in the comma, it does require the third argument. If you leave it out, it selects everything from the specified point to the end of the string.

    • #561809

      Sounds like your problem may be at table level and not with your code. The field in the table where you are storing this result may need the “Allow Zero Length” property set to “Yes. The default for this property is “No”.

      HTH
      RDH

      • #561869

        Tx Ricky

        That one I have under control. The field works fine if I actually key in the deletion even during the Debug sequence. But you are right sometimes it is the obvious things we miss.

      • #561897

        bravo bow Ricky

        I am so nuts blush frown

        I assumed (and you know what that does) because I could leave the field blank it was set for zero length strings. I went to the table just to check on the setting exclamation Problem solved. Thank you so much.

        BTW both solutions by Charlotte and Legare as well as my original work now.

        • #561929

          You are welcome ….. smile

          “Sometimes it’s the little things that get you”

          RDH

    • #561856

      Right$ can be used like this:

          MKRNT = Right$(C4R, Len(C4R)-1)
      
      • #561870

        Tx Legare

        I tried using the minus but I hadn’t figured out the “Len” bit and it told me it didn’t recognize my command. I spent some time looking at the “Len” thing this morning while Norton was doing its update. It looked promising but I thought I would have to do a couple more lines to identify the “Len”. Will try your suggestion today.

        Also just ran across something called “Trim”. It appears to only remove blanks but will experiment with it today also.

    Viewing 2 reply threads
    Reply To: How to delete 1 character frm a string (Office pro 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: