How do I prevent a line break in a form field?

N

numbercruncher88

How do I prevent a form user from entering a "return" character - it is
dropping the form line down and messes everything up. Also , if you limit
the form field to 10 text characters, can you size the form to 10 characters?
So that way the form is locked and doesn't change as the user enters the
information in the blank lines?
 
T

Tony Jollans

You can reassign the Enter key so that it does nothing ..

Sub DummyReturnKey()
End Sub

Sub ToggleReturnKey()
CustomizationContext = ActiveDocument
Set Key = FindKey(BuildKeyCode(wdKeyReturn))
If Key.KeyCategory = wdKeyCategoryNil Then
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="DummyReturnKey"
Else
Key.Clear
End If
End Sub

The Toggle routine will toggle the effect of the return key - either normal
or assigned to the empty sub above. Use at appropriate points (or extract
appropriate code from it and use that at appropriate points) such as
document_open and document_close.
 
S

Stefan Blom

And for the second question, place the form field in a table cell with
fixed dimensions.

--
Stefan Blom
Microsoft Word MVP


in message
 

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