SilentAiche
Technical User
Bear with me, this is going to be a long one. I'm using Word 2002 on Win XP.
I have a 14 page document saved as a form, with about a dozen small independent tables. There are several hundred Form Fields that the user tabs between to complete the document, including check boxes, table cells and basic memo-type fields.
Everything was working fine until I realized a user could hit Enter while in a field and Word would insert a hard carriage return (at least that's what I call it). A paragraph marker. This occurs in table cells and memo-type fields, not check boxes.
To my surprise, when I posted this problem on Jan. 31 it drew no replies. However, a Google search led me to the following code that seems to work well:
With this code in place, the Enter key now behaves like the Tab key. However, for this code to work each Form Field must have a Bookmark name, or else hitting Enter produces a Runtime 5941 error ("requested member does not exist"). I am currently going through this entire document and naming each bookmark.
THE PROBLEM (at last): Under Tools\Options\View I have checked Bookmarks to that I can visually tell if a Form Field already has a bookmark. The bookmarks are flagged by square gray brackets [ ] around the field. However, in several tables the brackets appear where no Form Field exists. Picture the following three-column table, where all the zeroes are in bookmarked Form Fields.
Reported Verified
Free [0] [0]
Reduced [0] [0]
Denied [0] [0]
T[otals] [0] [0]
Bookmark brackets mysteriously appear in the word "Totals," where there is no bookmark (it's not even a Form Field), and they have the effect of causing the Enter key to generate the error mentioned above. I cannot highlight, select or DELETE the brackets (which is the heart of the problem). However, if I type between them, they move to keep the text within the brackets. In some tables the brackets occur multiple times. In one case, an actual bookmarked Form Field appears to be overlaid with the mystery brackets. It appears like one of the numeric fields above, but with an extra space before the last bracket: [0 ]. Turning off the bookmark view does not solve the problem.
Sorry for the length of this. All thoughts welcome!
THanks,
Tim
I have a 14 page document saved as a form, with about a dozen small independent tables. There are several hundred Form Fields that the user tabs between to complete the document, including check boxes, table cells and basic memo-type fields.
Everything was working fine until I realized a user could hit Enter while in a field and Word would insert a hard carriage return (at least that's what I call it). A paragraph marker. This occurs in table cells and memo-type fields, not check boxes.
To my surprise, when I posted this problem on Jan. 31 it drew no replies. However, a Google search led me to the following code that seems to work well:
Code:
Sub EnterKeyMacro()
' 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
With this code in place, the Enter key now behaves like the Tab key. However, for this code to work each Form Field must have a Bookmark name, or else hitting Enter produces a Runtime 5941 error ("requested member does not exist"). I am currently going through this entire document and naming each bookmark.
THE PROBLEM (at last): Under Tools\Options\View I have checked Bookmarks to that I can visually tell if a Form Field already has a bookmark. The bookmarks are flagged by square gray brackets [ ] around the field. However, in several tables the brackets appear where no Form Field exists. Picture the following three-column table, where all the zeroes are in bookmarked Form Fields.
Reported Verified
Free [0] [0]
Reduced [0] [0]
Denied [0] [0]
T[otals] [0] [0]
Bookmark brackets mysteriously appear in the word "Totals," where there is no bookmark (it's not even a Form Field), and they have the effect of causing the Enter key to generate the error mentioned above. I cannot highlight, select or DELETE the brackets (which is the heart of the problem). However, if I type between them, they move to keep the text within the brackets. In some tables the brackets occur multiple times. In one case, an actual bookmarked Form Field appears to be overlaid with the mystery brackets. It appears like one of the numeric fields above, but with an extra space before the last bracket: [0 ]. Turning off the bookmark view does not solve the problem.
Sorry for the length of this. All thoughts welcome!
THanks,
Tim