Link to home
Start Free TrialLog in
Avatar of sspatel80
sspatel80

asked on

How do you make checkboxes behave like radio buttons in a word form

I have a word form with 4 checkboxes called Rare, Unlikely, Possible, Likely and Almost_Certain.  I want them to behave like radio buttons where only one checkbox can be selected at any one time.  

I have written a macro called MutuallyExChkBox that's been assigned to each checkbox and runs on entry. However this is a hit and miss solution-sometimes it work and other times it will allow more than one checkbox to be selected.  Any other fool proof solution would be much appreciated!

This is my current code:

Sub MutuallyExcChkBox()
 
If ActiveDocument.FormFields("Rare").CheckBox.Value = True Then
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False

ElseIf ActiveDocument.FormFields("Unlikely").CheckBox.Value = True Then
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False

ElseIf ActiveDocument.FormFields("Possible").CheckBox.Value = True Then
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False

ElseIf ActiveDocument.FormFields("Likely").CheckBox.Value = True Then
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False

ElseIf ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = True Then
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False

End If
 
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Flyster
Flyster
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also try this you may want to keep the checkbox always to true even the user click on same checkbox again

ie

Private Handle As Boolean
Private Sub Almost_Certain_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = True
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
Handle = False
End Sub

Private Sub Likely_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields("Likely").CheckBox.Value = True
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False
Handle = False
End Sub

Private Sub Possible_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields("Possible").CheckBox.Value = True
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False
Handle = False
End Sub


Private Sub Rare_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields("Rare").CheckBox.Value = True
ActiveDocument.FormFields("Unlikely").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False
Handle = False
End Sub


Private Sub Unlikely_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields("Unlikely").CheckBox.Value = True
ActiveDocument.FormFields("Rare").CheckBox.Value = False
ActiveDocument.FormFields("Possible").CheckBox.Value = False
ActiveDocument.FormFields("Likely").CheckBox.Value = False
ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = False
Handle = False
End Sub
Avatar of sspatel80
sspatel80

ASKER

Thank you both for you help.  Tick boxes are working perfectly.
I have another issue. One out of the above mentioned checkbox needs to to be selected followed by one of the following checkboxes : Neglible, Minor, Medium, Major, Catastrophic

There is a macro attached to each of these checkbox (Neglible, Minor, Medium, Major, Catastrophic) so that once a combination of two checkboxes are ticked eg 'Rare' and 'Medium' text appears in two form fields.

My question is how do I incorporate the click event similar to the one above into the existing macro thats linked to these checkboxes so that these checkboxes also also behave like radio buttons? I just can't work out how to do this.

Here is the macro for selecting "Negligible"

Sub Negligible()


Dim MyText2 As String

MyText2 = "2 = High risk - Senior Management attention required. The Occupational Health and Safety Coordinator" & _
          "is to be contacted immediately. Hazard controls must be implemented within 24 hours. Area must be restricted" & _
          "to prevent any incidents from occurring."


Dim MyText3 As String

MyText3 = "3 = Moderate risk - Department Manager attention required." & _
              "The Occupational Health and Safety Coordinator  must be notified within 24 hours." & _
              "Relevant controls are to be reviewed and implemented within a week. Where appropriate," & _
              "visual controls should be put in place to prevent any incidents from occurring."




If (ActiveDocument.FormFields("Rare").CheckBox.Value = True And ActiveDocument.FormFields("Negligible").CheckBox.Value = True) Then
ActiveDocument.FormFields("Description").Result = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields("Risk_Score").Result = "4"


ElseIf (ActiveDocument.FormFields("Unlikely").CheckBox.Value = True And ActiveDocument.FormFields("Negligible").CheckBox.Value = True) Then
ActiveDocument.FormFields("Description").Result = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields("Risk_Score").Result = "4"

ElseIf (ActiveDocument.FormFields("Possible").CheckBox.Value = True And ActiveDocument.FormFields("Negligible").CheckBox.Value = True) Then
ActiveDocument.FormFields("Description").Result = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields("Risk_Score").Result = "4"

ElseIf (ActiveDocument.FormFields("Likely").CheckBox.Value = True And ActiveDocument.FormFields("Negligible").CheckBox.Value = True) Then
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Description").Range.Fields(1).Result.Text = MyText3
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
ActiveDocument.FormFields("Risk_Score").Result = "3"

ElseIf (ActiveDocument.FormFields("Almost_Certain").CheckBox.Value = True And ActiveDocument.FormFields("Negligible").CheckBox.Value = True) Then
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("Description").Range.Fields(1).Result.Text = MyText2
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
ActiveDocument.FormFields("Risk_Score").Result = "2"

ElseIf ActiveDocument.FormFields("Negligible").CheckBox.Value = False Then
ActiveDocument.FormFields("Description").Result = ""
ActiveDocument.FormFields("Risk_Score").Result = ""
De-selection as a bit hit and miss-Checkbox immediately next to the selected checkboxe didn't always become de-selected.