Protecting Word doc with form fields

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Protecting Word doc with form fields

Post by AlanMiller »

I'm running into a problem with formfields being reset to default values, when I unprotect then reprotect a document from within VBA. According to Troubleshoot forms - Word - Microsoft Office
When you protect a form by using the Protect Document task pane (Tools menu, Protect Document command), information in form fields is automatically reset. This does not occur when you protect your document by using the Protect Form button on the Forms toolbar.
So I'm guessing my code:

Code: Select all

Activedocument.Protect wdAllowOnlyFormFields
is emulating the former method. Is there any way to emulate the latter, so that I don't lose data?

thanks
Alan

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Protecting Word doc with form fields

Post by StuartR »

You need to use

Code: Select all

Activedocument.Protect wdAllowOnlyFormFields, NoReset
StuartR


User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: Protecting Word doc with form fields

Post by AlanMiller »

StuartR wrote:You need to use

Code: Select all

Activedocument.Protect wdAllowOnlyFormFields, NoReset
Thanks Stuart. Too simple once you know how! :grin:

But I did find "NoReset" (as it appears in intellisense) wouldn't work as above. I needed to use:

Code: Select all

.Protect wdAllowOnlyFormFields, True
Alan

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Protecting Word doc with form fields

Post by HansV »

NoReset is the name of the argument. You can either specify arguments by position:

ActiveDocument.Protect wdAllowOnlyFormFields, True

or by name

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

If you specify them by name, you can change the order:

ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
Best wishes,
Hans

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: Protecting Word doc with form fields

Post by AlanMiller »

HansV wrote:NoReset is the name of the argument. You can either specify arguments by position:

ActiveDocument.Protect wdAllowOnlyFormFields, True

or by name

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

If you specify them by name, you can change the order:

ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
Thanks Hans. Despite lots of years, that's always one of the VB "quirks" I forget when (very) rusty. The other is syntax for arguments for procedure calls.

Alan

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Protecting Word doc with form fields

Post by StuartR »

Sorry, I answered this very quickly at about 05:15 this morning as I was going out.
StuartR


User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: Protecting Word doc with form fields

Post by AlanMiller »

No problem and it got me where I needed to go regardless. If I wasn't so out of touch with VB I'd have picked up on the syntactical quirk automatically. :grin:

cheers
Alan