Resetting Form Fields

R

Robin1979

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
 
D

Doug Robbins - Word MVP

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
 

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