Solved

Advise on best way to handle multiple checkboxes

Posted on 2014-11-14
7
163 Views
Last Modified: 2014-11-14
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
0
Comment
Question by:SteveL13
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 250 total points
ID: 40442685
You're using the wrong control. This is a classic radio button group.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40442692
place the check boxes in an Option Group.
0
 
LVL 35

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40442743
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 49

Expert Comment

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

/gustav
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40442784
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
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40442800
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
 
LVL 35

Expert Comment

by:PatHartman
ID: 40442818
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export to Excel 7 33
Help in SQL 13 37
90 days before current date 12 30
Run Stored Procedure uisng ADO 5 20
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question