Checkbox Validation

R

rjshrader

I need help with validating check-boxes on an unbound MS access form.

On my form I have various text boxes and four (4) check-boxes for
users to submit data to a table. I have a command button on the form
that when clicked verifies that the various text box controls are not
empty otherwise it displays a message to correct and sends the use
back to the form without saving.

What I need assistance with is with the 4 check-boxes I want to
validate that at least 1 of the boxes has been checked . If all are un-
checked I want to display a message (I know how to write the code for
the message) but I am not sure how to go about validating the check-
boxes.

Many thanks

-shrader
 
D

Doc Rock

If the checkbox is checked, it is True, or -1. Thus, your On_Exit or
Before_Update could be

If (CB1 + CB2 + CB3 + CB4) =-4 Then
MsgBox("One must be checked!")
CB1.SetFocus
Else
Do other stuff and
Exit
End If

Hope that helps..

Steve
 
R

rjshrader

If the checkbox is checked, it is True, or -1. Thus, your On_Exit or
Before_Update could be

If (CB1 + CB2 + CB3 + CB4) =-4 Then
MsgBox("One must be checked!")
CB1.SetFocus
Else
Do other stuff and
Exit
End If

Hope that helps..

Steve









- Show quoted text -

Thank you Steve,

I have added the code to the onclick event of my command button that
starts the validation process of the form and then saves the record to
the table. I receive a Run-time error 13 type mismatch error when the
code is executed.

-Shrader
 
G

Guest

Thank you Steve,

I have added the code to the onclick event of my command button that
starts the validation process of the form and then saves the record to
the table. I receive a Run-time error 13 type mismatch error when the
code is executed.

-Shrader


Without actually *seeing* your code, it is hard to say what the problem is.
What line causes the error? The code must have worked before you made
changes... so it is in the new code.

Did you change "CB1" through "CB4" to the names of your checkboxes?

Are the first two lines of the module:

Option Compare Database
Option Explicit

Did you compile the code? ( Menu bar DEBUG / COMPILE)



BTW, if you want to ensure that *at least* one check box is checked, you
should change the line
If (CB1 + CB2 + CB3 + CB4) =-4 Then


to

If (CB1 + CB2 + CB3 + CB4) = 0 Then
MsgBox ......


The only way the sum could be zero is if all 4 check boxes are unchecked.
 

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