VBA is Make Pairs of Check Boxes Mirror Each Other?

P

PBJ

In a protected Word form, I have three pairs of FormField check boxes: Check4
and Check14; Check 5 and Check15; and Check6 and Check16. I need to program
them so that, for each pair, if one is checked by a user, its counterpart
becomes checked as well automatically. The set-up needs to be fully
reciprocal, so that as soon as a user checks EITHER box in a pair, the other
one will follow suit. If Check4 is checked, for example, the macro needs to
check Check14. If a few minutes later, the user decides to uncheck Check14,
Check4 needs to uncheck, too.

I've tried macros like the following for a single pair of boxes:

Sub MirrorCheck()
With ActiveDocument
If .FormFields("Check4").CheckBox.Value = True Then
..FormFields("Check14").CheckBox.Value = True
Else
..FormFields("Check14").CheckBox.Value = False
End If
End With
End Sub

But I have no idea A) how to make even this macro fully reciprocal, or B)
how to get the other pairs of boxes involved without writing three separate
macros. Is what I want to do even possible? I'm totally stumped. Help!
 
B

Bear

PBJ:

So Sub MirrorCheck would be your exit macro (or would be called by the exit
macro) for every check box, right? Here's modified code from ProFieldNav
(protected field navigation) that lets you determine which formfield you just
exited from.


Sub proFieldNav()

Dim strCurrBookmark As String

If Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then
strCurrBookmark = Selection.Bookmarks(Selection.Bookmarks.Count).Name
Else
strCurrBookmark = Selection.FormFields(1).Name
End If

Select Case strCurrBookmark
Case "Check4"
ActiveDocument.FormFields("Check14").CheckBox.Value =
ActiveDocument.FormFields("Check4).CheckBox.Value
Case "Check5"
etc.
End Select

End Sub


If the relationship between the complement check boxes is always that
difference of 10, then you shold be able to extract the numeric portion of
the bookmark name and manipulate it to generate the complement check box name
for the currently selected checkbox. Then you'd have a general routine to set
their values equal.

Failing that, you could store the complement pairs in an array and read the
array until you find the selected bookmark, then extract the complement
bookmark from the other column in the array.

Sorry this is so general.

Bear
 

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