Link to home
Start Free TrialLog in
Avatar of ddelboccio
ddelboccio

asked on

Forms toolbar in Word 2002

When using the Forms toolbar in Word, specifically the "text form field", after defining the maximum length of the text field and locking/protecting the document, I still need the ability to prevent that text field from growing vertically by simply hitting the enter key.  I can tell the field to only allow 10 characters and it will stop accepting text after 10 characters, but how do I prevent it from becoming multiple lines if and when a user simply hits enter?
Avatar of R_Rajesh
R_Rajesh

Try disabling the retrun key for that form field. Add the following three routines to your document. Set the text form field's entry and exit macro to EntryMacro & ExitMacro

Sub EntryMacro()
CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="none"
End Sub

Sub ExitMacro()
CustomizationContext = ActiveDocument.AttachedTemplate
FindKey(KeyCode:=BuildKeyCode(wdKeyReturn)).Disable
End Sub

Sub none()
End Sub
Avatar of ddelboccio

ASKER

Please provide detail on how to "add" the routines you listed.  Thanks!
Open your document and hit alt+f11. This will open the VBE window. Select module form the insert menu and paste the routines. Close the VBE window. Back in word, right click the text field and select properties. You can set the entry and exit macros from this dialog.
OK.....I just tried this, and when I set the macros in the field as you described, protected the document and clicked on the text field in question, I received this error message (pop-up window):

Microsoft Visual Basic
run-time error '5980'
The context cannot be modified.

The window provided me with "end", "debug" or "help" buttons as well......
clicking debug highlighted this section:

KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="none"

with a yellow arrow pointing to the beginning of the second line
On the Tools menu, click Unprotect Document. Save, close, reopen and try again.
If this works, we can modify the code appropriately.
Unprotected, saved, closed, reopened.....now cannot protect the document.  Option is greyed out.
Are you using the default Normal.dot template?
Open explorer. Goto Tools-Folder options-View. Here select Show hidden files and folders.
Close all your documents, browse to C:\Documents and Settings\Your Login Name\Application Data\Microsoft\Templates. Cut normal.dot from this folder and paste it on your desktop. Open your document again.

That didn't make a difference.  I am saving this docuemnt I working on each time as a DOT itself.  Should I not be?  All previous versions I have saved still allow me to protect the docuement.  Is has only been since I used the ALT-F11 command and pasted in those routines you gave me, then saved the document again as a new DOT that I cannot re-protect it.
ASKER CERTIFIED SOLUTION
Avatar of R_Rajesh
R_Rajesh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK.......finally got it to work, but I think I am misunderstanding the concept here.  I have created the template, created the new document based on the template, but each time I open that new document and make changes to it, it will always ask whether or not to also save the template?  My end result is to try and make a standalone, read-only form that users open up in Word, can enter text in certain fields, then choose "SAVE AS" to save the document with their edits as a regular Word doc for their own files.  All along, not being able to change the original template/document.  Where did I turn wrong?  I was able to do this much easier in Adobe making an interactive PDF out of this, but Adobe Reader will not allow users to save what they changed on the PDF for their own use.  That is why I am trying to do this in Word.

I appreciate you sticking with me on this question!