How do I uncheck a checkbox?

LidaRose

New member
Local time
, 21:18
Joined
May 27, 2009
Messages
2
I'm using Access 2003 and am creating simple data entry forms for survey results. I'm pretty comfortable using all the wizards but am not a coder.

I want the Access form to look exactly like the original questionnaire on which there were several yes/no questions. Therefore, I want the Access form to show two choices (one for 'Yes' and one for 'No') for those questions.

I've set those fields up as 'Text' data types, no default values, and 'not required' in the table. On the form, I've created an option box with checkboxes: 'Yes'=value of 1, 'No'=value of 2. All works fine until I accidentally check a question where there actually was no response - I can't then 'uncheck' it. I can change the response from 'y' to 'n' or vice versa, but I can't clear the field all together.

I've tried changing the data type to 'Y/N' in the table, but then I only show one checkbox on the form which doesn't meet the criteria of having the form match the questionnaire. Creating a third choice in the option box of 'No Response' (with a '0' value) also doesn't meet the criteria. Radio buttons didn't make a difference either.

Is there a way to make this work?
 
Why not use a normal check box?? Is much easier :)
 
Why not use a normal check box?? Is much easier :)

He would like the form to match the paper questionaire, which has both a yes and a no check box :)

Well, first off, keep the field as a yes/no data type. You can use the options group as well. Set the value of Yes to -1 and the value of No to 0 and have the value stored in the yes/no field of the table. I am assuming that the form is bound to the table you are using to store the questionaire data.
 
Thanks but neither suggestion solves my problem. I actually had already tried both.

Yes, the form is bound to the table.

This only becomes an issue when during data entry a box is checked by accident for a question where there was actually no response at all. I want the field for that question to show nothing at all. But once a box is checked for a question, it seems like Access is demanding a value and will not let me 'uncheck' (or clear) a field without going into the table and deleting the response.

For example: if the person skipped question 1, but during data entry I accidentally check 'yes', I cannot 'uncheck' the box to clear the value now entered in the table. I can change the 'yes' to 'no' but cannot clear the response all together.

This is easily done in Filemaker - but I can't figure it out in Access and can't find it in their 'Help' either.
 
Have you tried setting the checkbox to NULL?
 
So, in effect, there are 3 possible answers to a question: Yes, No, Neither

If that is the case, a yes/no field will not work. There are a couple of ways you can do this. Off the top of my head, I thought of this:

Change the answer to Text. On the form, put 2 check boxes. one for yes, one for no. On the Click event for the Yes check box put the following:

Code:
If Me.chkYes = -1 Then
  Me!YesNo = "Yes"
    End If
If Me.chkNo = 0 And Me.chkYes = 0 Then
    Me!YesNo = "None"
    End If
If Me.chkNo = -1 And Me.chkYes = -1 Then
    MsgBox ("You cannot have both a Yes and No. Please change your answer")
    End If

for the click event for the No check box, put the following:

Code:
If Me.chkno = -1 Then
  Me!YesNo = "No"
    End If
If Me.chkNo = 0 And Me.chkYes = 0 Then
    Me!YesNo = "None"
    End If
If Me.chkNo = -1 And Me.chkYes = -1 Then
    MsgBox ("You cannot have both a Yes and No. Please change your answer")
    End If

This wont work if the Form is continuous because the check boxes are not unbound.

Of course, the easiest way to resolve this is to have a combo box with 3 entries (Yes, No, None). But then that would stray from the desire to have the form look like the questionaire.
 
LidaRose,

I would suggest that, in this case because you want to be able to actually have three values that might be stored in your field, you change the field type to a number type field and set the type to Byte. Set the default value for the field to zero (0).

Next you can use two independent checkboxes and use code very simular to what has already been proposed, except that you will not have to deal with the text strings you can simpley apply the numbers of zero = no selection, 1 = yes and 2 = no. You will then be able to set up a query that will present the data as string values when you are reporting on it.

You would have the followint controls on your form for each question:
chkYes - an unbound checkbox with the name of "chkYes"
chkNo - an unbound checkbox with the name of "chkNo"
txtYesNo - a bound text box bound to your YesNo field that is now a number

Next use code like the following in the after update event of the "Yes" checkboxes:
If me.chkYes = true then
Me.chkNo = false
Me.txtYesNo = 1
Else
Me.txtYesNo = 0
End If

Use code like the following in the after update event of the "No" checkboxes:
If me.chkNo = true then
Me.chkYes = false
Me.txtYesNo = 2
Else
Me.txtYesNo = 0
End If

HTH
 

Users who are viewing this thread

Back
Top Bottom