Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Oregon, USA
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    Charlotte

  3. #3
    Star Lounger
    Join Date
    Dec 2001
    Location
    Birmingham, Alabama USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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
    Ricky Hicks
    Microsoft MVP
    Birmingham, Alabama USA

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Right$ can be used like this:

    <pre> MKRNT = Right$(C4R, Len(C4R)-1)
    </pre>

    Legare Coleman

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Oregon, USA
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  6. #6
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Oregon, USA
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  7. #7
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Oregon, USA
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    Charlotte

  9. #9
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Oregon, USA
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30> <img src=/S/bow.gif border=0 alt=bow width=15 height=15> Ricky

    I am so <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15> <img src=/S/blush.gif border=0 alt=blush width=15 height=15> <img src=/S/frown.gif border=0 alt=frown width=15 height=15>

    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 <img src=/S/exclamation.gif border=0 alt=exclamation width=15 height=15> Problem solved. Thank you so much.

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

  10. #10
    Star Lounger
    Join Date
    Dec 2001
    Location
    Birmingham, Alabama USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    You are welcome ..... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    "Sometimes it's the little things that get you"

    RDH
    Ricky Hicks
    Microsoft MVP
    Birmingham, Alabama USA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •