suppress

R

rob p

Word 2003 template. The template is a large table with form fields and check
boxes in cells along with text.

If the check box is checked, I want the form field and text to show.

If not, I want the cell with it's check box, form field and text to be
suppressed. I have 10 cells on the page so I would need to program each one
to do that.

Is there a way of doing this?
Thanks.
 
A

Astrid

Hi Rob,

This depends on how your table looks. Assuming that checkbox, formfield and
text are all in one cell, you can use code like this that formats the entire
cell's font black or white. Select the ToggleHideCell procedure as the on
exit macro of the checkbox.

---------------------------------------------------------------------------------------------------------------------
Sub ToggleHideCell()
Dim oCell As Cell

Set oCell = Selection.Cells(1)
ToggleProtectDocument
If ActiveDocument.FormFields(FormfieldName()).CheckBox.Value = True Then
oCell.Range.Font.Color = wdColorBlack
Else
oCell.Range.Font.Color = wdColorWhite
End If
ToggleProtectDocument

End Sub

Sub ToggleProtectDocument()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
ElseIf ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End Sub

Function FormfieldName() As Variant

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

End Function

---------------------------------------------------------------------------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
 
R

rob p

Excellent idea. I tried the code and it works. Is there any other way to
trigger the macro other than exit of field? Alot of my users use the mouse
to check the box and don't tab thru the whole form. That leaves the last
field (macro) not run.
Thanks.
Rob
(I also tried using gray instead of white - works in the same way with none
choices grayed 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