PDA

View Full Version : Solved: Determine if paragraph mark is in a string



clhare
09-19-2007, 09:07 AM
Is it possible to check a value in a textbox (or a string) to see if it contains a paragraph mark or return? I assume I'd use InStr to check, but what would I check for?

TonyJollans
09-19-2007, 09:20 AM
It varies from place to place. chr(10) is a line feed; chr(13) is a carriage return. The terminology is from typewriter days and strictly incorrect.

Some containers use one, some the other, some both. There are VBA constants for them: vbLF, vbCR, vbCRLF. There is also vbNewLine which is be OS-sensitive - on a PC it is the same as vbCRLF.

clhare
09-19-2007, 09:46 AM
Is there a way to prevent the user from using the <Enter> key in a textbox?

TonyJollans
09-19-2007, 09:58 AM
What type of textbox?

I don't think ActiveX ones accept them anyway
Form ones can be validated on exit
In Drawing ones they can't easily be stopped

fumei
09-19-2007, 10:22 AM
Yes, Cheryl, try and be specific when you mention "textbox". There are too many things called "textbox". Is it a textbox on a userform? Is it a formfield textbox? Is it an ActiveX textbox in the document? Is it one of those Insert > Textbox?

An ActiveX textbox will accept Chr(13) - a paragraph mark (vbCrLf) - if MultiLine = True. However you must use Shift-Enter to make them. So if you do NOT want them, make MultiLine = False, the default anyway. This applies to both ActiveX textboxes in the document, or textboxes on a userform.

clhare
09-19-2007, 12:02 PM
Sorry--it is a textbox on a userform. I want to prevent the user from hitting Enter while in the textbox. I tried changing the Multiline property of the textbox on the userform to False, but when I hit Enter while in the textbox, it automatically fires the code for the OK button. Why is that??

TonyJollans
09-19-2007, 01:42 PM
Probably because the OK button is set to be Default=True. When you press Enter in any control (that doesn't take the Enter key itself) the default button will fire.

clhare
09-20-2007, 02:57 AM
Wow--I never realized that! I'll switch the default on the OK button to false. Thank you!