How to delete the last entry in textbox

Sohaila Taravati

Registered User.
Local time
Today, 15:28
Joined
Oct 24, 2001
Messages
266
Hi everybody,

I have a form that has buttons on it just like a keyboard and when I click the letters it sorts out a bunch of words and then I choose the word to put in a text box. Let's say that I put in "Queen Size Bed, Bedroom damaged". Each words that you see here is choosen out of my list box (This is a touch screen and I want my users not to type).

Everything works fine. But let's say I want to delete the word "damaged" and ony the word "damaged". How do I do it? Right now I do have a delete button that deletes the whole thing, but I want to be able to only delete the last entry.

Any help would be wonderful!

Thanks :)
 
What version of Access are you using?
 
I am using 2002 version.
 
OK, assuming your text box control is called "txtTextBox", try this:


Me.txtTextBox=Left(Me.txtTextBox,InstrRev(Me.txtTextBox, " ")-1)
 
Thank you very much, it worked. But it gives me an error message when it is trying to delete the very last item. "Invalid Procedure call or argument"

Thanks again :)
 
I only put up some basic code to work with the example you gave. Can you post an example of what text you have in the text box when that error comes up?
 
If I have 5 words in the text box, the code will delete them one by one when I click my undo button with the code you gave me. The problem occurs when I delete the very last word and that message comes up. I did put my own error message to prevent that message to come up, but if there is nothing in my txtbox, the stupid access message appears.

Thanks for your help :)
 
OK, so if the box is blank, you get the Access message?

Try doing something like this:
Code:
If Not IsNull(Me.txtTextBox) Then
    
Me.txtTextBox=Left(Me.txtTextBox,InstrRev(Me.txtTextBox, " ")-1)
End If
It will just prevent the code from running if the text box is empty.
 
I already did that, I just forgot to Exit Sub. It is working just perfect now. Thanks again for your help. :) :D
 

Users who are viewing this thread

Back
Top Bottom