Disable checkboxes when one is selected

Beaurou

New member
Local time
Today, 10:23
Joined
Jan 3, 2017
Messages
8
I have a form with 8 checkbox on it. What I want to achieve is whenever a checkbox is selected all the other one become unable (only one selection allowed). I try this code but it doesn't work. Did I use the good event procedure or should I use a different one? For the purpose of this Post I used only my first 4 checkbox

Proc_Perf
Proc_Value
Tech_Perf
Tech_Value

Private Sub Form_AfterUpdate()

If proc_pref Then
Me.Proc_Value.Enabled = False
Me.Tech_Value.Enabled = False
Me.Tech_Perf.Enabled = False

ElseIf Proc_Value Then
Me.Tech_Value.Enabled = False
Me.Proc_Perf.Enabled = False
Me.Tech_Perf.Enabled = False

ElseIf Tech_Pref Then
Me.Tech_Value.Enabled = False
Me.Proc_Perf.Enabled = False
Me.Proc_Value.Enabled = False
Else
Me.Tech_Perf.Enabled = False
Me.Proc_Perf.Enabled = False
Me.Proc_Value.Enabled = False
End If
End Sub

I do not know where is my problem, I still can select any of the check box when I selected one. I can even select the 4 of them. Your help will be greatly appreciated.
 
code needs to go in the afterupdate event of the tick box e.g.Private Sub proc_pref_AfterUpdate()Me.Proc_Value.Enabled = not proc_prefMe.Tech_Value.Enabled = not proc_prefMe.Tech_Perf.Enabled =not proc_prefend subPrivate Sub Proc_Value_AfterUpdate(Me.Proc_Ref.Enabled = not Proc_ValueMe.Tech_Value.Enabled = not Proc_ValueMe.Tech_Perf.Enabled =not Proc_Valueend subetc
sorry - can't get formatting buttons to work!
 
Thank CJ_London

It work good, the only problem it's when I move from one record the another the focus stay on the previous selected checkbox. I need the focus to be on the selected checkbox whenever I moved from record to record.
 
don't understand - is this a continuous form or datasheet? If so, then you need to use conditional formatting, not vba code
 
It's a form. Your script work good for my 8 checkboxes. But when I moved from one record to another I need the focus to be on the selected checkbox.
 
but what type of form? Single? Continuous? datasheet? Split?You would need some code in the form current event to set focus to the required control
 
It's a single form with the record selected on the bottom left.
 
Just to throw out an alternative, since they can only select one, I would probably have a single field that contained the selected value. You could use a combo or listbox, or an option group to make the selection. The combo/listbox would be most dynamic, since the choices could come from a table (a 9th option flows through automatically). The option group would visually be most similar to what you have.
 
Last edited:
still not clear to me but try the following. Apologies in advance for the layout since I can't get any formatting to work...1. At the top of the form module put a variableDim ctrlname as string...2. in each of your checkbox after update events putctrlname="Proc_Perf"changing name for each control...3. in the form current event putif nz(ctrlname)"" then me(ctrlname).setfocus...also have you tried setting the tab order so it happens automatically?
 
did wonder about suggesting an option group, but that does not lend itself to disabling the other options - they would all be disabled so user could not untick to then select another option.
 
With an option group, I'm not sure the other options need to be disabled. I interpreted the goal as preventing the selection of more than one option. The option group only allows one selection, so selecting one will deselect any others.
 
I agree...I assume that the 'disabling' of the others really means only allowing one choice out of the group...in which case the Option Group really is the appropriate/native way to do this.

Linq ;0)>

P.S. Glad to see that the formatting is working, again...I spent a quite a bit of time, earlier, trying to figure out what was wrong! :banghead:
 

Users who are viewing this thread

Back
Top Bottom