• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1517
  • Last Modified:

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
0
sspatel80
Asked:
sspatel80
  • 3
1 Solution
 
FlysterCommented:
Make a seperate click event for each checkbox:

Sub Rare_Click()

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
End If

End Sub

Sub Unlikely_Click()

If 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
End If

End Sub

Sub Possible_Click()

If 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
End If

End Sub

Sub Likely_Click()

If 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
End If

End Sub

Sub Almost_Certain_Click()

If 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

Flyster
0
 
EDDYKTCommented:
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
0
 
sspatel80Author Commented:
Thank you both for you help.  Tick boxes are working perfectly.
0
 
sspatel80Author Commented:
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 = ""
0
 
sspatel80Author Commented:
De-selection as a bit hit and miss-Checkbox immediately next to the selected checkboxe didn't always become de-selected.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now