Unprotecting Forms

S

Susan B. Quinn

I have set up a template that directs the user to fill in specific
information and as it exits the last field it runs and unprotect macro. It
appears that some users are finding it deletes the information when it
unprotects.

Note: I don't want to reprotect the document.

I have tried the various macros as suggested by Doug, Jay and friends but
for some reason it continues to reset even though the macro is designed not to

These are the two codes I used so far.

Sub ToolsProtectUnprotectDocument()

Dim oDoc As Document
Set oDoc = ActiveDocument

If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
.noreset = True
.Show
End With
Else
oDoc.unprotect
End If
Exit Sub

Selection.GoTo What:=wdGoToBookmark, name:="start"

End Sub


Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.unprotect
End If

End Sub


Any enlightening assistance would be appreciated.
 
O

old man

Hi,

You seem to have an exit sub in the wrong place in the
ToolsProtectUnprotectDocument subroutine. Once Word hits exit sub it does not
process any more of the the instructions in the subrountine so the goto will
never happen.

Please provide more info on when data disappears.

old man
 
S

Susan B. Quinn

The goto is the least of my problems. The data is deleted when the macro
unprotects the document. I have removed that exit sub and I still have the
same problem.

Susan
 
O

old man

Hi,

When you turn on protection make sure you use the following code:
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
endif

This should preserve the contents of the fields.

old man
 
S

Susan B. Quinn

I have worked out the problem. The macro was being run on exit from the last
field in the document. That seem to reset the form every time no matter what
you did.

I have set up a button for the user to click on when they want to run the
macro and the data doesn't disappear.

Strange - don't know why - but it works and that's all that counts.

Thank you for your help.
 

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