(Excel 2010)
Sometimes I seem to be blind and can't see the obvious
I'm building a form; several check-boxes; two problems:
(1) When I click one checkbox, I want two others to uncheck and vv. So in the "Sub Chk1_Click()", I do: "Myform.Chk2=false"
But the latter triggers the "Sub Chk2_Click()" (where I do the opposite). So I added "Application.EnableEvents=False" before (and True) after the Chk2=false call. That doesn't stop the other sub from triggering however... I must be overlooking something simple...
(2) One of my checkboxes is smaller (the font is the same, but the box is smaller)... where did that come from and how do I undo this?
Checkboxes in a form
-
- BronzeLounger
- Posts: 1244
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
-
- Administrator
- Posts: 78492
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Checkboxes in a form
1) Use option buttons (aka radio buttons) instead of check boxes, and assign the same GroupName property. The user will then be able to turn on only one of the option buttons.
2) Hopefully, this problem will be gone when you replace the check boxes with option buttons.
2) Hopefully, this problem will be gone when you replace the check boxes with option buttons.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1244
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Checkboxes in a form
I did that in another form; for this one I need check boxes as multiple choices are allowed. I need to intervene as in two cases, options don't match. So I need checkboxes. In summary; how do I programmatically switch one off if I select another one and v.v. (without using optionboxes).
Any idea about the size?? It's quite odd... I manually added them and compared all properties; still one check-mark is smaller than the other...
Any idea about the size?? It's quite odd... I manually added them and compared all properties; still one check-mark is smaller than the other...
-
- Administrator
- Posts: 78492
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Checkboxes in a form
Define a Boolean variable at the top of the module and use that to control when the event procedures perform their actions:
I'd have to see the form to be able to answer your other question.
Code: Select all
Private blnStop As Boolean
Private Sub Chk1_Click()
If blnStop Then Exit Sub
blnStop = True
Me.Chk2 = False
blnStop = False
End Sub
Private Sub Chk2_Click()
If blnStop Then Exit Sub
blnStop = True
Me.Chk1 = False
blnStop = False
End Sub
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1244
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Checkboxes in a form
Thanks, that works!
The sizes; I'm still playing around...
The sizes; I'm still playing around...