Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
place the check boxes in an Option Group.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No points, but Stephan and Pat are right. You are reinventing the radiobutton control. Not a good idea.

/gustav
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
Technically true, but using checkboxes will violate the design guides, thus confusing users, which is just about the last thing you should do.

/gustav
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