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").Ch eckBox.Val ue = True Then
ActiveDocument.FormFields( "Unlikely" ).CheckBox .Value = False
ActiveDocument.FormFields( "Possible" ).CheckBox .Value = False
ActiveDocument.FormFields( "Likely"). CheckBox.V alue = False
ActiveDocument.FormFields( "Almost_Ce rtain").Ch eckBox.Val ue = False
ElseIf ActiveDocument.FormFields( "Unlikely" ).CheckBox .Value = True Then
ActiveDocument.FormFields( "Rare").Ch eckBox.Val ue = False
ActiveDocument.FormFields( "Possible" ).CheckBox .Value = False
ActiveDocument.FormFields( "Likely"). CheckBox.V alue = False
ActiveDocument.FormFields( "Almost_Ce rtain").Ch eckBox.Val ue = False
ElseIf ActiveDocument.FormFields( "Possible" ).CheckBox .Value = True Then
ActiveDocument.FormFields( "Rare").Ch eckBox.Val ue = False
ActiveDocument.FormFields( "Unlikely" ).CheckBox .Value = False
ActiveDocument.FormFields( "Likely"). CheckBox.V alue = False
ActiveDocument.FormFields( "Almost_Ce rtain").Ch eckBox.Val ue = False
ElseIf ActiveDocument.FormFields( "Likely"). CheckBox.V alue = True Then
ActiveDocument.FormFields( "Rare").Ch eckBox.Val ue = False
ActiveDocument.FormFields( "Unlikely" ).CheckBox .Value = False
ActiveDocument.FormFields( "Possible" ).CheckBox .Value = False
ActiveDocument.FormFields( "Almost_Ce rtain").Ch eckBox.Val ue = False
ElseIf ActiveDocument.FormFields( "Almost_Ce rtain").Ch eckBox.Val ue = True Then
ActiveDocument.FormFields( "Rare").Ch eckBox.Val ue = False
ActiveDocument.FormFields( "Unlikely" ).CheckBox .Value = False
ActiveDocument.FormFields( "Possible" ).CheckBox .Value = False
ActiveDocument.FormFields( "Likely"). CheckBox.V alue = False
End If
End Sub
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(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both for you help. Tick boxes are working perfectly.
ASKER
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").C heckBox.Va lue = True And ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = True) Then
ActiveDocument.FormFields( "Descripti on").Resul t = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields( "Risk_Scor e").Result = "4"
ElseIf (ActiveDocument.FormFields ("Unlikely ").CheckBo x.Value = True And ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = True) Then
ActiveDocument.FormFields( "Descripti on").Resul t = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields( "Risk_Scor e").Result = "4"
ElseIf (ActiveDocument.FormFields ("Possible ").CheckBo x.Value = True And ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = True) Then
ActiveDocument.FormFields( "Descripti on").Resul t = "Low risk - Manage by routine procedures. Appropriate controls to be reviewed and implemented within 1 month where required. "
ActiveDocument.FormFields( "Risk_Scor e").Result = "4"
ElseIf (ActiveDocument.FormFields ("Likely") .CheckBox. Value = True And ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = True) Then
ActiveDocument.Unprotect
ActiveDocument.Bookmarks(" Descriptio n").Range. Fields(1). Result.Tex t = MyText3
ActiveDocument.Protect Type:=wdAllowOnlyFormField s, NoReset:=True
ActiveDocument.FormFields( "Risk_Scor e").Result = "3"
ElseIf (ActiveDocument.FormFields ("Almost_C ertain").C heckBox.Va lue = True And ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = True) Then
ActiveDocument.Unprotect
ActiveDocument.Bookmarks(" Descriptio n").Range. Fields(1). Result.Tex t = MyText2
ActiveDocument.Protect Type:=wdAllowOnlyFormField s, NoReset:=True
ActiveDocument.FormFields( "Risk_Scor e").Result = "2"
ElseIf ActiveDocument.FormFields( "Negligibl e").CheckB ox.Value = False Then
ActiveDocument.FormFields( "Descripti on").Resul t = ""
ActiveDocument.FormFields( "Risk_Scor e").Result = ""
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
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf (ActiveDocument.FormFields
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf (ActiveDocument.FormFields
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ElseIf (ActiveDocument.FormFields
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("
ActiveDocument.Protect Type:=wdAllowOnlyFormField
ActiveDocument.FormFields(
ElseIf (ActiveDocument.FormFields
ActiveDocument.Unprotect
ActiveDocument.Bookmarks("
ActiveDocument.Protect Type:=wdAllowOnlyFormField
ActiveDocument.FormFields(
ElseIf ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ASKER
De-selection as a bit hit and miss-Checkbox immediately next to the selected checkboxe didn't always become de-selected.
ie
Private Handle As Boolean
Private Sub Almost_Certain_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
Handle = False
End Sub
Private Sub Likely_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
Handle = False
End Sub
Private Sub Possible_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
Handle = False
End Sub
Private Sub Rare_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
Handle = False
End Sub
Private Sub Unlikely_Click()
If Handle = True Then Exit Sub
Handle = True
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
ActiveDocument.FormFields(
Handle = False
End Sub