Forced entry validation help please.

D

Dave myers

Hi,

I have checked previous posts and google and can't find an answer yet so...

I have an area in a form with 4 checkboxes, I need the user to select at
least one..How can this be done? Maybe a little VB or simpler, I can't use
radio buttons as they can select more than one box.

I also can't use simple validation as they have more than 1 option...is
there a way that when they tab through the options they will be presented
with a warning box telling them to select at least one option or some other
solution?

Thanks for any help...I am fairly new to this.

Dave
 
M

MarsGuy

Hi,

This is how I handle this type of "mandatory" input.

Create a textbox on the form, name it whatever you wish,
set its "Visible" property to No and set the default to 1.
On each of the check boxes write code in the On Click
Event that says Me![textboxyoucreated]=2. If ANY of the
check boxes are clicked the value of the textbox will be
2 instead of 1. On the button that is used to exit the
form (I never allow the Close Button to be used on a
form, I create a button with the On Click -
"DoCmd.Close") write:

If Me![textboxyoucreated]>1 Then
DoCmd.Close
Else
MsgBox "You must select one of the check boxes!", vbOKonly
End If

Hope this helps.
 
J

John Vinson

Hi,

I have checked previous posts and google and can't find an answer yet so...

I have an area in a form with 4 checkboxes, I need the user to select at
least one..How can this be done? Maybe a little VB or simpler, I can't use
radio buttons as they can select more than one box.

I also can't use simple validation as they have more than 1 option...is
there a way that when they tab through the options they will be presented
with a warning box telling them to select at least one option or some other
solution?

Thanks for any help...I am fairly new to this.

On a Form, you can use the Form's BeforeUpdate event to check for
valid input:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not(Me!chkOne OR Me!chkTwo OR Me!chkThree OR Me!chkFour) Then
MsgBox "Please check at least one of the four options", vbOKOnly
Cancel = True
End If
End Sub


John W. Vinson[MVP]
 
?

?????????

John Vinson said:
On a Form, you can use the Form's BeforeUpdate event to check for
valid input:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not(Me!chkOne OR Me!chkTwo OR Me!chkThree OR Me!chkFour) Then
MsgBox "Please check at least one of the four options", vbOKOnly
Cancel = True
End If
End Sub


John W. Vinson[MVP]
 
Top