From: Robin1979 on
Hi,
I have the following maco assigned to a check box in my form but it appears
as the macro lock and unlocks the form all the form fields are reset, even
though Ive got the No Reset option set to true it is still resetting them, is
there an easy way to over come this?

Thanks
Robin



Sub OnExitSite1a()
Dim bProtected As Boolean
Dim rText As Range
Dim oFld As FormFields
Dim sPassword As String
Set oFld = ActiveDocument.FormFields
Set rText = ActiveDocument.Bookmarks("CheckSiteResult1a").Range
sPassword = "" 'password if any to unprotect the form
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If
'Check whether CheckSite1a is checked
If oFld("CheckSite1a").CheckBox.Value = True Then
rText.Text = "WaddOrders please setup new site code"
Else
rText.Text = ""
End If
With ActiveDocument
.Bookmarks.Add "CheckSiteResult1a", rText
.Fields.Update
End With
'Reprotect the document.
Finished:
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPassword

End If
End Sub
From: Doug Robbins - Word MVP on
Why don't you insert a text formfield into the document and then use code to
set the .Result of that formfileld depending upon the state of the checkbox.
Then you do not need to unprotect and reprotect the form.

With the way that you are doing it, what is the purpose of the
..fields.update command. I suspect that it is the execution of that command
while the document is unprotected that is causing the formfields to be
reset.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Robin1979" <Robin1979(a)discussions.microsoft.com> wrote in message
news:4696D181-31AE-4E39-AF46-536BABB92C27(a)microsoft.com...
> Hi, I have the following Macro which I thought should not reset form
> fields
> but each time its used and it relocks the form the formfields are reset,
> please could someone be kind enough to point me in the right direction of
> where it is going wrong?
>
> Thanks
> Robin
>
> Sub OnExitSite1a()
> Dim bProtected As Boolean
> Dim rText As Range
> Dim oFld As FormFields
> Dim sPassword As String
> Set oFld = ActiveDocument.FormFields
> Set rText = ActiveDocument.Bookmarks("CheckSiteResult1a").Range
> sPassword = "" 'password if any to unprotect the form
> 'Unprotect the file
> If ActiveDocument.ProtectionType <> wdNoProtection Then
> bProtected = True
> ActiveDocument.Unprotect Password:=sPassword
> End If
> 'Check whether CheckSite1a is checked
> If oFld("CheckSite1a").CheckBox.Value = True Then
> rText.Text = "WaddOrders please setup new site code"
> Else
> rText.Text = ""
> End If
> With ActiveDocument
> .Bookmarks.Add "CheckSiteResult1a", rText
> .Fields.Update
> 'Reprotect the document.
> Finished:
> If bProtected = True Then
> ActiveDocument.Protect _
> Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPassword
> End If
> End Sub