How do I prevent CTRL-ENTER in my Text Boxes

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
 
A

Allen Browne

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.
 

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