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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check boxes. 2

Status
Not open for further replies.

sborny

Technical User
Jun 29, 2001
157
GB
Hi All,

I have 2 check boxes on a form and I need it so that only one can be checked at any one time. Ie if you click check2 and check1 is already ticked then check1 should untick and check2 should tick and visa versa.

I also need this to happen when you click on the labels nect to the check boses and not on the check boxes themselves.

Any help would be appreciated.

Kindest Regards

S.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
Hi

do you need to do this with checkboxes? can you not use radiobuttons which were designed for this purpose?
 
If you are determined to use check boxes you could do something like this:


Private Sub chkHigh_Click()
If chkHigh.Value = Checked Then
chkNormal.Value = Unchecked
chkUrgent.Value = Unchecked
End If
End Sub

Private Sub chkNormal_Click()
If chkNormal.Value = Checked Then
chkHigh.Value = Unchecked
chkUrgent.Value = Unchecked
End If
End Sub


Private Sub chkUrgent_Click()
If chkUrgent.Value = Checked Then
chkNormal.Value = Unchecked
chkHigh.Value = Unchecked
End If
End Sub

I've never done it but labels have a click event. I'm guessing you could interogate the check boxs in a similar fashion.
 
Hi,

Thanks for your help.

Yes I could use radio buttons instead of checkboxes but I have not used them before.

Could you help me with the code to do the same thing.

Thanks

S.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
Are you using vb6? if so then you have 2 options

1. just drag a few option buttons onto the page, by default you will only be able to select one of them

2. if you have different groups of options then its best to put each group in a frame.

To get the data back just query the value property of the individual option.
 
sborny,

Radio buttons (Option buttons) have their own labels the same as Checkboxes. When you click on the Button OR the label, the option will be selected.

As only one option button inside a work area (frame or form etc.) can be selected at once, when you click on another option, the previously selected on will be de-selected and the one you just clicked will be the new selection.
The option buttons are provided as a faster alternative to coding checkboxes for the same purpose.

Example:

In the example below I set the VALUE Property of the HIGH option to true at design-time.

image2.gif


When you click on the LOW option, the HIGH is de-selected automatically and the LOW becomes selected. i.e.

image3.gif


To code the option buttons, add your code into the CLICK event of the option button i.e.

For an option button in an array:
Code:
Private Sub optHigh_Click(Index As Integer)
    If Index = 0 then
        MsgBox "HIGH Selected",VBOKOnly,"Message"
    ElseIf Index = 1    
        MsgBox "LOW Selected",VBOKOnly,"Message"
    End if
End Sub

For an option button not in an array (eg. optHigh and optLow)
Code:
Private Sub optHigh_Click()
    MsgBox "HIGH Selected",VBOKOnly,"Message"
End Sub

Hope this helps.


jgjge3.gif
[tt]"Very funny, Scotty... Now Beam down my clothes."[/tt]
 
JAG14,
Awesome job on the explanation! Enjoy a Star on me.

Sam
 
Thank you JAG14 for you fantastic response.

I have put radio buttons on the form and all works well.

Have a star.

Thanks to all that have contibuted.

Cheers

S.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top