user forms and enter key

C

cmledbetter

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 normal.dot, 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
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 AutoClose()
CustomizationContext = ActiveDocument.AttachedTemplate
FindKey(KeyCode:=BuildKeyCode(wdKeyReturn)).Disable
' Disables prompt to save template changes.
Templates(1).Save
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

Templates(1).Save

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.

Cecil
 

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