Word, Form Fields and the Enter Key

I

iamnu

I'm using the code below to the Enter Key will behave like the Tab Key
to go between Form Fields.

The problem is that when using the Enter Key, the Form Fields do not
get Formatted, as they do with the Tab Key.

By the way, after using the Enter Key, if I go back to the previous
Form Field, and then exit that Form Field with a right arrow or Tab
Key, that Field will then show the proper formatting.

Can someone please show how to modify this code to work properly?

Thanks for your help,
Bernie
----------------------------------------------------------------------------------------------------------------
The code below was copied from here: http://support.microsoft.com/kb/211219

Sub EnterKeyMacro()
Dim myformfield
' Check whether the document is protected for forms
' and whether the protection is active.
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields And _
Selection.Sections(1).ProtectedForForms = True Then
' Retrieve the bookmark of the current selection.
' This is equivalent to the name of the form field.
myformfield = Selection.Bookmarks(1).Name
' Go to the next form field if the current form field
' is not the last one in the document.
If ActiveDocument.FormFields(myformfield).Name <> _
ActiveDocument.FormFields(ActiveDocument.FormFields.Count) _
.Name Then
ActiveDocument.FormFields(myformfield).Next.Select
Else
' If the current form field is the last one,
' go to the first form field in the document.
ActiveDocument.FormFields(1).Select
End If
Else
' If the document is not protected for forms,
' insert a tab stop character.
Selection.TypeText Chr(13)
End If
End Sub

Sub AutoNew()
' Do Not protect the template containing these macros.
CustomizationContext = ActiveDocument.AttachedTemplate
' Bind the ENTER key to the EnterKeyMacro.
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"

' Reprotect the document with Forms protection.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

Sub AutoOpen()
' This macro will reassign the ENTER key when you open an existing
' Word form fields document.
CustomizationContext = ActiveDocument.AttachedTemplate
' Bind the Enter key to the EnterKeyMacro.
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"
End Sub

Sub AutoClose()
CustomizationContext = ActiveDocument.AttachedTemplate
FindKey(KeyCode:=BuildKeyCode(wdKeyReturn)).Disable
' Disables prompt to save template changes.
Templates(1).Save
End Sub
 

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