Checkbox and field in the table

sessionone

New member
Local time
Today, 14:33
Joined
Feb 17, 2010
Messages
5
Hi,

Sorry if this is a dumb question, but I can't find an answer.

I have a few checkboxes on the form that if checked should fill one particular field in the table with text. I tried to set the source for the checkboxes to that field, but then I get -1.

I suppose I should assign a string value to the state of a checkbox but I'm not sure how to do this.

Could anyone please help?

thanks
 
Your best option is to use VBA code to accomplish this type of activity. The code would need to be in the After Update event of the check box and would be something like:

If me.chkNameOfCheckBox = -1 then
'write the value to the text box
Me.txtNameOfTextbox = "Some String Here"
Else
'if the check box is unchecked, clear the text box
Me.txtNameOfTextbox = ""
End If

You would of course need to change the "chkNameOfCheckBox" to the actual name of your checkbox and the "txtNameOfTextbox" to the actual name of the textbox where you want the text entered.

This process assumes that you have these text boxes on a form and bound to the appropriate field, even if they are not visible, so the text is entered into the field.
 
Last edited:
Your best option is to use VBA code to accomplish this type of activity. The code would need to be in the After Update event of the check box and would be something like:

If me.chkNameOfCheckBox = -1 then
and actually you don't need the = -1 part -

If Me.chkNameOfCheckBox Then

will suffice.
 
Thanks a lot :)

Just curious, is it possible to do this without the textbox?

Thanks again
 
As long as the FIELD is in the form's Record Source (it doesn't need to be on the form) you can use this code to set its value:
Code:
If Me.CheckBoxNameHere Then
   Me!FieldNameHere = "Whatever"
End If

Using the BANG (!) I'm telling Access I want to use the FIELD and not the control so it can find it.
 
Check boxes return True or -1 when check and False or 0 when unchecked.
 

Users who are viewing this thread

Back
Top Bottom