Select 1 and only 1 Form Field

EPamperin12

New Member
Joined
Jan 8, 2008
Messages
47
I have a form on Microsoft Word. I have 72 Differnet Questions that have FormField Checkboxes. I am wanting a better way to program each question to make sure 1 and only 1 checkbox was selected for each question. Some of my questions have numerous choices (up to 26).

I have something that works, but it is probably not the best way to program it. and would like some help.

Code:
Sub CheckQuestion1()
 Dim oDoc As Document
 Dim oFFs As FormFields
 Dim oRng As String
 Set oDoc = ActiveDocument
 Set oFFs = oDoc.FormFields

If oFFs("K70").CheckBox.Value = False _
     And oFFs("K71").CheckBox.Value = False _
     and oFFs("K72").CheckBox.Value = False Then
         Error.Label1 = "Please Select at least 1"
         Error.show
         offs("K70").Select
End if

If oFFs("K70").CheckBox.Value = True _
     if oFFs("K71").CheckBox.Value = False then
      or oFFs("K72").CheckBox.Value = False Then
         Error.Label1 = "Please Select at least 1"
     End if 
Elseif oFFs("K71").CheckBox.Value = False then
      if oFFs("K72").CheckBox.Value = False Then
         Error.Label1 = "Please Select at least 1"
     End if 
Else 
End if
End Sub

This is not bad for 2 or 3 options but I have some that are 26 different options. Any help on a way to shrink this code down would be most helpful.

Thank you.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
What I usually do is in the events, as soon as the user checks a box, it unchecks all the others. That way you don't need a message box, it simply wont let them have more than one checked at a time.

So something like:

Code:
Private Sub AU_Click()
If Sheets("Main").ToggleHelp Then
    'Shows my help file if the toggle was down for help
    Sheets("Main").ToggleHelp = False
    Territory_Help.Show
    End
Else
    Sheets("Main").NZ = False
End If
End Sub

So when the user checks the AU checkbox, it automatically unchecks the NZ (After it has checked to see if the user is asking for help).
 
Upvote 0
Thank you for your help, I was able to find another way solution. I am able to bypass running the macro on entry or exit on the form checkbox. So that is a problem with fixing it as they go. (Word is not as nice as Excel).
I worked around the problem by naming a variable and then if a box is checked.
Code:
Sub CheckQuestion1()
 Dim oDoc As Document
 Dim oFFs As FormFields
 Dim oRng As String
 Set oDoc = ActiveDocument
 Set oFFs = oDoc.FormFields
n = 0
If oFFs("K70").CheckBox.Value = True then n = n + 1
if oFFs("K71").CheckBox.Value = True then n = n + 1
if oFFs("K72").CheckBox.Value = True Then n = n + 1

     if n = 0 then 
          MsgBox "Please Select at least 1"
     Elseif n > 1 then 
          MsgBox "Please Select only 1"
     End if
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,363
Messages
6,184,518
Members
453,238
Latest member
visuvisu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top