How do I prevent CTRL-ENTER in my Text Boxes

  • Thread starter Thread starter Douglas
  • Start date Start date
D

Douglas

Is there a property or something i can code to stop users pressing
Ctrl-Enter in a text box and getting a new line.
I want my text boxes to be single line only as I use the fields on
reports and it is messing up some of the formatting.

TIA

Doug
 
Add this code to the KeyDown event of your text box:
If KeyCode = 13 And Shift = 2 Then
KeyCode = 0
End If

Use the KeyDown event of the Form if you want it to apply to all controls on
the form. Remember to turn KeyPreview on.

It won't stop users from pasting in a Carriage Return/Line Feed.
To do that also, you could use the AfterUpdate event of the control, with
the Replace function to find vbCrLf.
 
Back
Top