Protecting document

S

Starbird

I have a template that will have different types of users. I am trying to
set the protection to read only if the user selects one option in the
userform and to formfieldsonly if the user selects a different option. The
code I'm using is:

If Me.opEng.Value = True Then
ActiveWindow.ActivePane.View.ShowAll = True
ActiveDocument.Protect Password:="test", NoReset:=True,
Type:=wdAllowOnlyFormFields

ElseIf Me.opOperator.Value = True Then
ActiveWindow.ActivePane.View.ShowAll = False
ActiveDocument.Protect Password:="test", NoReset:=True,
Type:=wdAllowOnlyReading
End If

I must be leaving something out, I have tried several things but to no avail.
Thanks for any assistance!

SRD
 
H

headly

Well, a couple of things stand out here.

First, I don't see you correctly capturing the field value with the
Me.opEng.Value and Me.opOperator.Value variables. So if you step through the
code line by line with the F8 key, then mouse over the Me.opEng.Value you
will see if it's true or false and your other code executes or not;
Second on the ActiveDocument.Protect line I see a line break without an
underscore line break/continuation character so perhaps your code errors out
of the routine.
 
S

Starbird

It errors out on the ActiveDocument.Protect line, when I mouse over
wdAllowOnlyFormFields it says 'wdAllowOnlyFormFields = 2
(I think the line break you are seeing is because of space in the text area
here, there is no line break in my real code)
I used this code to set other things such as view, and it worked fine, so
there must be something different with the protection that I am unaware of.

Thanks for any help
 
S

Starbird

Thanks, I needed to remove current protection

headly said:
Well, a couple of things stand out here.

First, I don't see you correctly capturing the field value with the
Me.opEng.Value and Me.opOperator.Value variables. So if you step through the
code line by line with the F8 key, then mouse over the Me.opEng.Value you
will see if it's true or false and your other code executes or not;
Second on the ActiveDocument.Protect line I see a line break without an
underscore line break/continuation character so perhaps your code errors out
of the routine.
 
D

Doug Robbins

I assume that in your code, the ActiveDocument.Protect and the
wdAllowOnlyFormFields is all on the one line.

The following works fine for me:

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset, "test"

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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