dimanche 24 mars 2019

How to hide checkbox options when another checkbox is selected

I'm in the process of trying to put together a form in ms-word, in which it is desired that if a user checks 1 of 3 check-box options, the other two and their adjacent text will be hidden.

I'm aware of how to hide the content some-what, but I'm completely unfamiliar with VBA/programming as a whole, so I don't quite know what is wrong in my If/Else loop, but it definitely doesn't show/hide everything.

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

If ContentControl.Title = "checkbox1" And ContentControl.Checked = True Then
    ActiveDocument.Bookmarks("Approve").Range.Font.Hidden = True
Else
    ActiveDocument.Bookmarks("Approve").Range.Font.Hidden = False
End If

If ContentControl.Title = "checkbox2" And ContentControl.Checked = True Then
    ActiveDocument.Bookmarks("Denied 1").Range.Font.Hidden = True
    ActiveDocument.Bookmarks("Denied 2").Range.Font.Hidden = True
Else
    ActiveDocument.Bookmarks("Sign1").Range.Font.Hidden = False
    ActiveDocument.Bookmarks("Sign2").Range.Font.Hidden = False
End If

If ContentControl.Title = "checkbox3" And ContentControl.Checked = True Then
    ActiveDocument.Bookmarks("pending").Range.Font.Hidden = True
Else
    ActiveDocument.Bookmarks("pending").Range.Font.Hidden = False
End If

End Sub

If I only keep one of the if/else parts it does work fine, but when I keep all 3 it doesn't work.

Any guidance is really appreciated!




Aucun commentaire:

Enregistrer un commentaire