Advise on best way to handle multiple checkboxes

I'm looking for the best way to handle multiple Yes/No checkboxes.  If one is checked, true, the others have to be unchecked, false.  There are 5 individual checkboxes on the form.  I have the following code but it seems odd to have to have this code on each checkbox's afterupdate or onchange event.  Right?

    If Me.chkbx1 = True Then
        Me.chkbx2 = False
        Me.chkbx3 = False
        Me.chkbx4 = False
        Me.chkbx5 = False
    End If
        
    If Me.chkbx2 = True Then
        Me.chkbx1 = False
        Me.chkbx3 = False
        Me.chkbx4 = False
        Me.chkbx5 = False
    End If
        
    If Me.chkbx3 = True Then
        Me.chkbx1 = False
        Me.chkbx2 = False
        Me.chkbx4 = False
        Me.chkbx5 = False
    End If
        
    If Me.chkbx4 = True Then
        Me.chkbx1 = False
        Me.chkbx2 = False
        Me.chkbx3 = False
        Me.chkbx5 = False
    End If
        
    If Me.chkbx5 = True Then
        Me.chkbx1 = False
        Me.chkbx2 = False
        Me.chkbx3 = False
        Me.chkbx4 = False
    End If

Open in new window


--Steve
SteveL13Asked:
Who is Participating?
 
ste5anConnect With a Mentor Senior DeveloperCommented:
You're using the wrong control. This is a classic radio button group.
0
 
Rey Obrero (Capricorn1)Commented:
place the check boxes in an Option Group.
0
 
PatHartmanConnect With a Mentor Commented:
Using the option group will also mean that the control is bound to a single column in your table.  So, rather than having 5 checkbox fields, you will have a single integer and it will have a value of null (nothing checked) or 1-5 depending on which box is checked so you will probably have to change your queries if this data is used to select rows.

When you have a group of options that are mutually exclusive, you would use a single table column and either an option group (if the number of options is small and static) or a combo or list box (if the number of options is large or variable).
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Gustav BrockCIOCommented:
No points, but Stephan and Pat are right. You are reinventing the radiobutton control. Not a good idea.

/gustav
0
 
Rey Obrero (Capricorn1)Commented:
Option groups can have set of Option buttons, check boxes or toggle buttons.

you can select which one to use using the Option group Wizard
0
 
Gustav BrockCIOCommented:
Technically true, but using checkboxes will violate the design guides, thus confusing users, which is just about the last thing you should do.

/gustav
0
 
PatHartmanCommented:
One other thing to point out which if you've never used an option group isn't obvious and that is that you refer to the option group control in your code.  You never refer to the individual checkboxes or radio buttons within the option group.  So, if the name of the option group is fraOutputTo (fra for frame)

Select Case Me.fraOutputTo
  Case 1
        ''' print out
   Case 2
        ''' export to Excel
   Case Else
        ''' Open in print preview
End Select

Open in new window

0
All Courses

From novice to tech pro — start learning today.