Make Textbox entry "Add Only" ?

B

Bill

I have a textbox on a form that I want to allow users to append to but not
replace.
The textbox is loaded with a text string - say "My favorite Fruit is"

I want the user to be able to complete the sentence.

The text always changes so a mask does not make sense and I do not see an
easy way to do this with Format.

I thought about On Keydown but I'm not sure if there is an easier way.

Thanks

Bill
 
R

Rick B

Seems like you would make your statement the label, and then provide a text
box for the user to make their selection.
 
B

Bill

My example was not the best -

The real application is messaging where the user picks a message with a
listbox and if the message has the "customize" bool set then I allow them to
add to the message by throwing up a hidden textbox containing the message.

The problem is that the user can just backspace out the whole message and
write a new one.
I want the original message to stay and just allow them to append to it
before "Sending".

Bill
 
R

Rick B

I would still do it as two fields. Let them select the text in one field
(drop-down) then have a separate unbound text box for the last part of the
entry.

When you send the data, send your drop-down selection and concatenate the
textbox.
 
B

Bill

Makes sense but I would still prefer using a single textbox.

I will look at kestroke events to see if I can manage the .text on the fly
as they type.
The hard part is finding out where in the string they are typing - have not
figured that one out yet.

Bill
 
B

Bill

Never Mind - I got it.

Pretty simple really - here is the code for anyone interested

Private Sub txt2_KeyPress(KeyAscii As Integer)
Dim myLen, StartPos As Integer

myLen = Len(txt2.Value)
StartPos = txt2.SelStart

If StartPos < myLen Then
txt2.Text = txt2.Value
txt2.SelStart = myLen
End If

End Sub

The nice thing about this is if I want to keep the 1st 2/3 of the message
"Read Only"or 1st 10 characters then that is one extra line of code.

Bill
 
J

JohnGriffiths

See question inline.

Bill said:
Never Mind - I got it.

Pretty simple really - here is the code for anyone interested

Private Sub txt2_KeyPress(KeyAscii As Integer)
Dim myLen, StartPos As Integer

myLen = Len(txt2.Value)
StartPos = txt2.SelStart

If StartPos < myLen Then
txt2.Text = txt2.Value
txt2.SelStart = myLen
End If

End Sub

------------------------------

Right Click
Choose option Paste

Now what? John

------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top