Setting a checkbox field to the value received from Form/Screen

J

Jeffery B Paarsa

In a Word VBA code I am displaying a Form/Screen with lots of Checkboxes on
the form to the user. I would like to set the value of check boxes on the
word document to the value of check boxes coming from the form/screen by the
user. Here is the code I use:

Calling subroutine:

Private Sub CMDPage4N_Click()
With ActiveDocument
.Unprotect
UpdateCheckBox "SWgtLoss", ChkB01.Value
.Protect wdAllowOnlyFormFields
UserForm1.MultiPage1.Value = MultiPage1.Value + 1
End With
End Sub

Here is the Called Subroutine:

Public Sub UpdateCheckBox(BookmarkToUpdate As String, BoolData As Boolean)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
With ActiveDocument.FormFields(BookmarkToUpdate).CheckBox
.Value = BoolData
End With
End Sub

I turned on the debug on the following line in the calling subroutine:
UpdateCheckBox "SWgtLoss", ChkB01.Value
Having the document open at the back of the debug screen I can see the
related check box field is being set to X but as soon as I come out go to the
following line:
UserForm1.MultiPage1.Value = MultiPage1.Value + 1
my check box tunes into unchecked box and X is being removed. I think I
know I have call by value problem but I have used 3-4 hours to resolve this
problem and keep the X in the box with no success. Any suggestion?
 
J

Jezebel

I assume that "form/screen" is your own term for "UserForm". (The word
'form' usually means a document with formfields.)

1. When you re-protect the document, you need to use the 'noreset' argument.
Otherwise the formfields are cleared --

activedocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=true


2. In your UpdateCheckBox code you set BMRange, but then don't refer to it.
What did you have in mind with this?
 
J

Jeffery B Paarsa

Thank you it worked... Regarding the unsed variable ignore it I just tried to
post the code as brief as I could and I forgot to take them out...
 

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