#1
|
|||
|
|||
Preventing Form Fields to Reset
Greetings,
I have a WORD document that contains Form Fields for the user to enter information. This document is repeatedly used from one shift to another, it contains information for shift turnover. I want to FORCE the user to enable macros so that when the user closes the document, it automatically creates a 'archive' copy of the file, with the current date/time in the file name, saved to a different folder, for retrieval if something got fouled up. I attempted to protect the document from any changes upon closing, and then upon opening, I would unprotect the document, then re-protect it allowing 'Filling in forms'. When I do this, all the fields reset to empty. I don't want the user to have to retype everything, only edit what might have changed in the last shift, then save it. Here is my code: Code:
Private Sub Document_Close() With ThisDocument .Unprotect Password:="pw" .Protect Password:="pw", _ NoReset:=False, _ Type:=wdAllowOnlyReading, _ UseIRM:=False, _ EnforceStyleLock:=False End With End Sub Code:
Private Sub Document_Open() With ThisDocument .Unprotect Password:="pw" .Protect Password:="pw", _ NoReset:=False, _ Type:=wdAllowOnlyFormFields, _ UseIRM:=False, _ EnforceStyleLock:=False End With End Sub |
#2
|
||||
|
||||
Hi PosseJohn,
Change 'NoReset:=False' to 'NoReset:=True'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thankyou, setting the NoReset:=True now prevents the form fields from going blank.
Followup question: Using the code I previously posted, it seems that the VBA code doesn't protect the document after AllowOnlyReading. When I reopen the document, without enabling macros, the FormFields are still able to be edited. When troubleshooting, I stepped thru the VBA code by using F8, and the code seemed to work just fine. But when the code runs on its own, it doesn't. Any suggestions? Thanks!! |
#4
|
||||
|
||||
Hi PosseJohn,
What you need to do is to lock each formfield. For example: Code:
Private Sub Document_Close() Dim fFld As FormField, Pwd As String Pwd = "pw" With ThisDocument .Unprotect Password:=Pwd For Each fFld In .FormFields fFld.Enabled = False Next .Protect Password:=Pwd, NoReset:=True, _ Type:=wdAllowOnlyFormFields, _ UseIRM:=False, EnforceStyleLock:=False End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Very well, I will give it a go. Thank you for your quick response and sharing of the knowledge.
G'Day |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tab through fields on a form. | Keep on Ticking | Word | 1 | 06-23-2011 03:29 AM |
Calculating Form Fields in Microsoft Word | wubba80 | Word | 1 | 06-25-2010 12:42 AM |
Form Fields Problem | shogan | Word | 1 | 05-18-2010 01:01 AM |
Form fields in Word messed up | mba | Word VBA | 0 | 02-07-2010 09:54 PM |
Form Fields | questions | Word | 0 | 04-27-2009 10:48 AM |