enter line break in textbox

jesse

Registered User.
Local time
Today, 02:21
Joined
Jul 14, 2010
Messages
39
Hi,

I have a (rich text) textbox on one of my forms. I'd like the user to be able to use the enter key to go to a new line. As I found out the enter key does not normally behave that way in a textbox I am trying to solve this through vba code. I came as far as the following:

Private Sub mail_text_Enter()
mail_text.Value = mail_text.Value & "<br />"
mail_text.SetFocus
End Sub

which is wildly unsuccesfull as it only adds a line break at the end of the text (I don't know how to get the cursor position) and it doesn't even set focus back to the textbox.

I feel I'm going totally the wrong way about this. Does someone know how to do this?

thanks!

Jesse
 
In the property of your textbox, select the Other Tab and change the Behavior of Enterkey from standard to NewLine in field.

JR
 
The easiest way (obviously except for JANR's explanation above) is to get the users to hold down Control key when they want to enter a return.

Generally speaking you can use one of the On Key events to trigger action with keys
Here is KeyDown.
http://msdn.microsoft.com/en-us/library/aa211398(office.11).aspx

Use the SelStart property of the textbox to get the cursor position.
http://msdn.microsoft.com/en-us/library/aa196578(office.11).aspx

BTW, the On Enter event is about moving into the control not the Enter Key.
 

Users who are viewing this thread

Back
Top Bottom