Multiple Selection, Select Just One

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Multiple Selection, Select Just One

Post by burrina »

I have several check boxes and want the user to be able to select just one of them.The others should be De-Selected.
Example:

Code: Select all

If Me.admn.Value = -1 Then
    Me.sprvsr.Value = 0
    Me.data.Value = 0
    Me.reado.Value = 0
    Me.exclu.Value = 0
  End If
Must be easier way. I am using the AfterUpdateEvent of the check boxes event. Here are the controls and the data type and format.
admn
sprvsr
data
reado
exclu


Check Boxes
Data Type Yes/No
Format Yes/No



{RESOLVED}
Last edited by burrina on 31 Dec 2016, 20:34, edited 1 time in total.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Multiple Selection, Select Just One

Post by Rudi »

Ideally you should use option buttons for that. If you can replace the check boxes with option buttons, that will be an immediate advantage (that only one in the group can be selected.)
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Multiple Selection, Select Just One

Post by HansV »

I'd use option buttons (radio buttons) instead of check boxes. The interface convention is to use option buttons if you want to allow only one choice, and check boxes if you want to allow multiple choices.
Create an Option Group control (frame), and create (or paste) the option buttons in this option group.
Assign a different Option Value to each option button in the Data tab of the Property Sheet, for example 1, 2, 3 and 4.
When you click an option button, Access will automatically turn off the other option buttons in the same option group, without needing any code.

If you do it this way, you don't inspect the value of the individual option buttons (or check boxes) in order to check which one has been selected. Instead, you inspect the value of the option group control. This will be equal to the Option Value of the selected option button. So if you selected the option button with Option Value 3, the value of the option group will be 3.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: Multiple Selection, Select Just One

Post by burrina »

Can't change design. It is this way for a reason. I understand the reasoning though. This is on a Continuous form.
Thanks,

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Multiple Selection, Select Just One

Post by HansV »

If you can't place the check boxes in a content control, you'll have to use code like what you posted at the beginning of this thread.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Multiple Selection, Select Just One

Post by Pat »

You could use a combo box with just 5 entries, defined as a list