SteveL13
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?
--Steve
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
--Steve
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
place the check boxes in an Option Group.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
No points, but Stephan and Pat are right. You are reinventing the radiobutton control. Not a good idea.
/gustav
/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
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
/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