user forms and enter key



I have three user forms that are used from a network location that utilizes
code that changes the behavior of the enter key to emulate the tab key. The
code was posted in kb Article ID: 187985. These forms have worked well until
recently. Now my users are experiencing two different problems.

1. This problem seems to be related to just a single user. Her enter key is
no longer working within Word documents (works as expected when in a user
form). I suspect that somehow the autoclose routine did not complete but I
cannot find a means to correct this. Suspected that possibly a user had
inadvertently saved some code to her, but his is not the case.
Complete code to follow:

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 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
' If the current form field is the last one,
' go to the first form field in the document.
End If
' If the document is not protected for forms,
' insert a tab stop character.
Selection.TypeText Chr(13)
End If
End Sub
Sub AutoClose()
CustomizationContext = ActiveDocument.AttachedTemplate
' Disables prompt to save template changes.
End Sub

2. Second problem seems to be related to the autoclose routine. When the
users exit the user form they receive a message as follows: “Word cannot save
this file because it is already open elsewhere.†And the message points our
network location. This dialog box only allows a response of OK which think
brings up the debugger and error code 5995, Word cannot write this file,
which then moves tis line of code


If we end the debugger the routine continues on to request user to save the
document created with the user form.

I hope this makes a little sense to someone and any advice is appreciated.



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