Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mutually exclusive check boxes

Status
Not open for further replies.

davext

Programmer
Oct 6, 2003
18
CA
Does anyone know how to create mutually exclusive check boxes?

Have 2 check boxes, only one can be checked at a time. I know this can be done with a control array for radio buttons but I want to do it with check boxes. I've tried manipulating the values of the checkbox but this doesn't seem to work properly.

Thanks for the help.
 
Private Sub Check1_Click()
If Check1.Value = 1 Then
Check2.Value = 0
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Check1.Value = 0
End If
End Sub

Experience is something you don't get until just after you need it.
 
Thanks for responding but this is what I've tried before. It doesnt' work. What ends up happening is, I click on check1, a check mark appears, then I click on check 2, and a check mark appears while check one still has a check mark, but then when I click on check1 again, both disappear. I don't know why it works that way.
 
What's happening in your event code? I usually use a module level boolean to show whether or not to execute events in these circumstances, and set it false if I'm actually processing a user driven event.

Nb. I think you'll find setting value actually generates a click event (Which it bally well shouldn't!)

Martin
 
I created a test project. Proved that it worked and pasted the code into the thread.

It works fine for me, honest.

Experience is something you don't get until just after you need it.
 
If you want to simulate radio buttons then use this.

Private Sub Check1_Click()
If Check1.Value = 1 Then
Check2.Value = 0
ElseIf Check1.Value = 0 Then Check2.Value = 1
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Check1.Value = 0
ElseIf Check2.Value = 0 Then Check1.Value = 1
End If
End Sub


Experience is something you don't get until just after you need it.
 
I have the same set up and it doesn't work. What's up with that?

In my event code? please elaborate. All I have is the same simple code that bigalbigal showed me.
 
Sweet! It works, thanks a lot for your help!

Thanks to mmilan too!
 
>I don't know why it works that way.

I suspect you were using True/False instead of 1/0

Experience is something you don't get until just after you need it.
 
I believe I know what my initial problem was. I was using the check1_validate event instead of the click event. Can someone explain what the difference is? THanks
 
See also thread222-541865. It presents a code to handle two or more check boxes using a much simple and generalized method. It uses a control array of check boxes to make a mutually exclusive set working in a group.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top