usform check boxes
Wow...a lot of code. You would think there would be an easier way!
--
Thanks
Shawn
"Dave Peterson" wrote:
One way is to use something like application.enableevents to stop the changes in
your code from firing the _click events for the other checkboxes.
I created a small userform with 5 checkboxes and a commandbutton on it. This
was the code behind the userform:
Option Explicit
Dim BlkProc As Boolean
Dim MaxCheckBoxes As Long
Dim NoneOfTheseCBXNumber As Long
Private Sub CheckBox1_Click()
If BlkProc = True Then Exit Sub
Call ChkCheckBoxes(1)
End Sub
Private Sub CheckBox2_Click()
If BlkProc = True Then Exit Sub
Call ChkCheckBoxes(2)
End Sub
Private Sub CheckBox3_Click()
If BlkProc = True Then Exit Sub
Call ChkCheckBoxes(3)
End Sub
Private Sub CheckBox4_Click()
If BlkProc = True Then Exit Sub
Call ChkCheckBoxes(4)
End Sub
Private Sub CheckBox5_Click()
If BlkProc = True Then Exit Sub
Call ChkCheckBoxes(5)
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Sub ChkCheckBoxes(myNum As Long)
Dim iCtr As Long
Dim NoneOfTheseCBX As Control
Set NoneOfTheseCBX = Me.Controls("Checkbox" & NoneOfTheseCBXNumber)
If myNum = NoneOfTheseCBXNumber Then
If NoneOfTheseCBX.Value = True Then
BlkProc = True
For iCtr = 1 To MaxCheckBoxes
If iCtr = NoneOfTheseCBXNumber Then
'skip it
Else
Me.Controls("checkbox" & iCtr).Value = False
End If
Next iCtr
End If
Else
BlkProc = True
NoneOfTheseCBX.Value = False
End If
BlkProc = False
End Sub
Private Sub UserForm_Initialize()
MaxCheckBoxes = 5 'how many checkboxes?
NoneOfTheseCBXNumber = 3 'any one you want
Me.Controls("Checkbox" & NoneOfTheseCBXNumber).Caption = "None of these"
End Sub
====
I did rely on the fact that all the checkboxes had nice names: Checkbox1, ...,
checkbox5. So I could loop through them easily.
Shawn wrote:
I have a userform with several check boxes on it. Users can click as many as
appropriate. The last option is "None of these". If the user clicks any
check box other than the "None of these" it changes the value of "None of
these" to false. If the user clicks the "None of these" checkbox it changes
the value of all other checkboxes to false.
My problem is, for example, when the user clicks "None of these" it clears
the others but leaves the "None of these" option blank. You have to click it
a 2nd time to change its value to true????? I want one click to clear the
others and change the value of the "None of these" option to true. I know I
have a circular reference. How do I get around this?
If
--
Thanks
Shawn
--
Dave Peterson
|