Problem clearing checkboxes when a different option is chosen on dropdown.

K

kalfonso82

I am having trouble having the previous checkboxes cleared and the correct
checkboxes chosen when a different dropdown option is chosen.

Please look at my code below and see where I have made my mistake.

Sub riskCodeDrop()

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 2 Then
ActiveDocument.FormFields("autoBox").CheckBox.Value = True
ActiveDocument.FormFields("end0735Box").CheckBox.Value = True
ActiveDocument.FormFields("end0809Box").CheckBox.Value = True
ActiveDocument.FormFields("end0811Box").CheckBox.Value = True
End If

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 5 Then
ActiveDocument.FormFields("motoBox").CheckBox.Value = True
ActiveDocument.FormFields("end0809Box").CheckBox.Value = True
ActiveDocument.FormFields("end0810Box").CheckBox.Value = True
ActiveDocument.FormFields("end0811Box").CheckBox.Value = True
End If

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 4 Then
ActiveDocument.FormFields("rvBox").CheckBox.Value = True
ActiveDocument.FormFields("end0809Box").CheckBox.Value = True
ActiveDocument.FormFields("end0811Box").CheckBox.Value = True
ActiveDocument.FormFields("end0812Box").CheckBox.Value = True
End If

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 3 Then
ActiveDocument.FormFields("truckBox").CheckBox.Value = True
ActiveDocument.FormFields("end0809Box").CheckBox.Value = True
ActiveDocument.FormFields("end0811Box").CheckBox.Value = True
End If

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 1 Then
ActiveDocument.FormFields("autoBox").CheckBox.Value = False
ActiveDocument.FormFields("motoBox").CheckBox.Value = False
ActiveDocument.FormFields("rvBox").CheckBox.Value = False
ActiveDocument.FormFields("truckBox").CheckBox.Value = False
ActiveDocument.FormFields("end0735Box").CheckBox.Value = False
ActiveDocument.FormFields("end0809Box").CheckBox.Value = False
ActiveDocument.FormFields("end0809Box").CheckBox.Value = False
ActiveDocument.FormFields("end0810Box").CheckBox.Value = False
ActiveDocument.FormFields("end0811Box").CheckBox.Value = False
ActiveDocument.FormFields("end0812Box").CheckBox.Value = False
End If

If ActiveDocument.FormFields("riskCodeDrop").DropDown.Value = 6 - 21 Then
ActiveDocument.FormFields("autoBox").CheckBox.Value = False
ActiveDocument.FormFields("motoBox").CheckBox.Value = False
ActiveDocument.FormFields("rvBox").CheckBox.Value = False
ActiveDocument.FormFields("truckBox").CheckBox.Value = False
ActiveDocument.FormFields("end0735Box").CheckBox.Value = False
ActiveDocument.FormFields("end0809Box").CheckBox.Value = False
ActiveDocument.FormFields("end0809Box").CheckBox.Value = False
ActiveDocument.FormFields("end0810Box").CheckBox.Value = False
ActiveDocument.FormFields("end0811Box").CheckBox.Value = False
ActiveDocument.FormFields("end0812Box").CheckBox.Value = False
End If



End Sub
 
G

Graham Mayor

You must set the values of *all* the check boxes the dropdown affects and
you may find it simpler to track if you use Case statements

Sub riskCodeDrop()
With ActiveDocument
Select Case .FormFields("riskCodeDrop")
Case Is = 2
.FormFields("autoBox").CheckBox.Value = True
.FormFields("motoBox").CheckBox.Value = False
.FormFields("truckBox").CheckBox.Value = False
.FormFields("rvBox").CheckBox.Value = False
.FormFields("end0735Box").CheckBox.Value = True
.FormFields("end0809Box").CheckBox.Value = True
.FormFields("end0810Box").CheckBox.Value = False
.FormFields("end0811Box").CheckBox.Value = True
.FormFields("end0812Box").CheckBox.Value = False
Case Is = 3
.FormFields("autoBox").CheckBox.Value = False
.FormFields("motoBox").CheckBox.Value = False
.FormFields("truckBox").CheckBox.Value = True
.FormFields("rvBox").CheckBox.Value = False
.FormFields("end0735Box").CheckBox.Value = False
.FormFields("end0809Box").CheckBox.Value = True
.FormFields("end0810Box").CheckBox.Value = False
.FormFields("end0811Box").CheckBox.Value = True
.FormFields("end0812Box").CheckBox.Value = False
Case Is = 4
.FormFields("autoBox").CheckBox.Value = False
.FormFields("motoBox").CheckBox.Value = False
.FormFields("truckBox").CheckBox.Value = False
.FormFields("rvBox").CheckBox.Value = True
.FormFields("end0735Box").CheckBox.Value = False
.FormFields("end0809Box").CheckBox.Value = True
.FormFields("end0810Box").CheckBox.Value = False
.FormFields("end0811Box").CheckBox.Value = True
.FormFields("end0812Box").CheckBox.Value = True
Case Is = 5
.FormFields("autoBox").CheckBox.Value = False
.FormFields("motoBox").CheckBox.Value = True
.FormFields("truckBox").CheckBox.Value = False
.FormFields("rvBox").CheckBox.Value = False
.FormFields("end0735Box").CheckBox.Value = False
.FormFields("end0809Box").CheckBox.Value = True
.FormFields("end0810Box").CheckBox.Value = True
.FormFields("end0811Box").CheckBox.Value = True
.FormFields("end0812Box").CheckBox.Value = False
Case Else
.FormFields("autoBox").CheckBox.Value = False
.FormFields("motoBox").CheckBox.Value = False
.FormFields("truckBox").CheckBox.Value = False
.FormFields("rvBox").CheckBox.Value = False
.FormFields("end0735Box").CheckBox.Value = False
.FormFields("end0809Box").CheckBox.Value = False
.FormFields("end0810Box").CheckBox.Value = False
.FormFields("end0811Box").CheckBox.Value = False
.FormFields("end0812Box").CheckBox.Value = False
End Select
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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