Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change value of text box

Status
Not open for further replies.

pigsie

Programmer
Joined
Dec 19, 2000
Messages
307
Location
GB
Hi

Is it possible to programmitcally add items to the content of a textbox *at the current cursor position*? I am creating a form with a number of buttons. when the user clicks on a button I would like to insert text at the current icon position within the textbox. Can this be done?

Thanks in advance
 
Sure you can but one question...if the user has to click outside of the text box then the cursor position in that field is lost? You cannot reference the .SelStart (cursor pos) when the control has lost focus.
 
Thats okay - basically I will be creating a form allowing the user to do an email mail merge, so I will have 6 or so buttons such as name , age , dob etc. clicking on a button will insert specific text into the text field maybe something like $surname$, $age$, $dob$ which I can then replace when doing the email mail merge
 
The you can use the following.

Code:
Private Sub cmdYourbutton_Click()

   Me.txtYourfieldname = "text to insert"

End Sub
 
Just to clarify - will that simply insert the text in place of the current text or will it insert it where the cursor currently is?
 
Just tried it - it doesn't, it completly replaces the current text - I know I can append to the current text but I actually want to insert based on where the cursor is
 
Yes, the example i gave you shows you how to update the field. As I said to you earlier...if you do this from a button, you can only append to the end of the existing data. This example will append to the end of whatever data is in that text box originally. Are you saying ' where the cursor is' to mean the end of the existing data?

Code:
Private Sub cmdYourbutton_Click()

   Me.txtYourfieldname = Me.txtYourfieldname & "text to insert"

End Sub
 
Have a look at thread705-1024251, but also thread702-1029041.

Roy-Vidar
 
Roy thanks for the links, the first thread explained exactly what I wanted to do (but clearer than I explained it) thanks for all the suggestions guys - I will give it a try -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top