check boxes

B

brino

hi all !

i have 4 check boxes for 4 different fields.
on a form i have, the user can only select 1 only.
how do i test if only 1 has been ticked & then alert the user if more
than 1 has been ticked ??
thanks

brino
 
W

Wayne-I-M

Hi Brino

Behind each check box put an action on the BeforeUpdate event - something
like this
Change the check box names (I have used 0, 1, 2 and 3)

Private Sub Check0_BeforeUpdate(Cancel As Integer)
If (Forms!tester!Check0 = -1 Or Forms!tester!Check1 = -1 Or
Forms!tester!Check2 = -1) Then
Beep
MsgBox "tester", vbOKOnly, "this is a test"
End If
End Sub
Private Sub Check1_BeforeUpdate(Cancel As Integer)
If (Forms!tester!Check0 = -1 Or Forms!tester!Check0 = -1 Or
Forms!tester!Check3 = -1) Then
Beep
MsgBox "tester", vbOKOnly, "this is a test"
End If
End Sub
Private Sub Check2_BeforeUpdate(Cancel As Integer)
If (Forms!tester!Check0 = -1 Or Forms!tester!Check2 = -1 Or
Forms!tester!Check3 = -1) Then
Beep
MsgBox "tester", vbOKOnly, "this is a test"
End If
End Sub
Private Sub Check3_BeforeUpdate(Cancel As Integer)
If (Forms!tester!Check1 = -1 Or Forms!tester!Check2 = -1 Or
Forms!tester!Check3 = -1) Then
Beep
MsgBox "tester", vbOKOnly, "this is a test"
End If
End Sub

Of course you need to change the word "Tester" and the message box title
"this is a test" to whatever you want.

Hope this helps
 
J

JK

Why not use Option Button? This will enure that only one option is selected.

Regards/JK
 
V

Van T. Dinh

Beware that you may have the wrong Table Structure / Fields if you use 4
Boolean Fields but only one of them can be True.

It sound to me that a single Field (byte) with 4 possible values 1, 2, 3, 4
and each one represent one of your required True's. Since these values are
mutually exclusive (each Field can be of 1 of 4 values only), this resembles
more to your requirements. In addition, you can simply use an Option Frame
on your Form and the user can select only 1 value out of 4.
 
W

Wayne-I-M

Hi Brino

After thinking about it a bit more (and a few coffees) I agree with Van's
idea that you should not have 4 option boxes that will not allow the other
options (exclusive) and also that JK's idea would be a better way to
progress. If you used an option group you could use something like this
AfterUpdate

Private Sub OptionGroupName_AfterUpdate()
Select Case Me!OptionGroupName
Case 1
Insert something
Case 2
Insert something here
Case 3
Insert something here
Case 4
Insert something here
End Select
End Sub

Hope this helps

Oh, don't forget there is a wizard to help you with option groups if your
not really sure about them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top