By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

How to Insert CheckBox values into the tables

P: 15
Hi all,

I have a check box in a form and field in the correspoding table is also a check box.How to insert the value of the check box to that table?
When I check the check box on the form and press enter it is not automatically checking or setting the value of the field in the table.

I have retrieved the value of the check box on the form by using following code:

Dim Temp
Temp = Me.Form.Controls("DisabledChkBox").Value

I got the value of it as -1 i.e the checkbox is checked. Now how to enter this value into the table, I mean how to set the checkbox in that table.

I have another fields along with this checkbox and I am using simple
DoCmd.RunSQL "INSERT into Tbl Values ();" query

The only problem I am facing is when I insert all the values only the fieilds related to checkboxes are not updated.

Please help me resolving this

Thanks,
Pdesh3
Jul 23 '07 #1
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,366
Is the record source of the form set to the table? Is the control source of the checkbox set to the field in the table? If both of these are true then the table should automatically update.
Jul 23 '07 #2

P: 15
Is the record source of the form set to the table? Is the control source of the checkbox set to the field in the table? If both of these are true then the table should automatically update.
Yeah, I have set both the fields. What should I write in the query so that when the check box on the form is set , the check box in table also is set?

I have kept the field in the table as yes/no type. So it is displaying check box in the table also.

If I use normal Insert query as { All the fields are normal text and number type , but a field with name 'Disabled' is a check box} shown below:

DoCmd.RunSQL "INSERT into [tblPatient] ([MRNumber], [SSN] , [FirstName], [MI], [LastName]) VALUES (MRNumber, SSN , FirstName, MI, LastName);"

Now my concern is how to insert the value of the checkbox. If I don't give Disabled field in the query list as shown below it is giving an error saying 'number of query values and destination fields are not same'.

If I give it like below :
DoCmd.RunSQL "INSERT into [tblPatient] ([MRNumber], [SSN] , [FirstName], [MI], [LastName], [Disabled]) VALUES (MRNumber, SSN , FirstName, MI, LastName, D);"
Where D is the variable holding the value of the checkbox (either 0 when not set or 1 when set).

Then when I am trying to insert values it is displaying a msgbox saying to enter the value of D.

Can you suggest me what changes I need to make to this query.

Thank you,
Pdesh3.
Jul 24 '07 #3

Rabbit
Expert Mod 10K+
P: 12,366
You can use the reserved words True and False. But the thing is, if your form is set up correctly then you don't need to use a DoCmd.RunSQL. It should be automatic.
Jul 24 '07 #4

P: 15
You can use the reserved words True and False. But the thing is, if your form is set up correctly then you don't need to use a DoCmd.RunSQL. It should be automatic.
Can you please give me what changes I need to make to the form so that the values are entered automatically.

I have kept Record Source of the form to corresponding table. What else I need to do?

Thanks,
Pdesh3
Jul 25 '07 #5

Rabbit
Expert Mod 10K+
P: 12,366
Post #2 lays out the changes you need to make. Also, check your Recordset Type property in your Form properties and make sure that's Dynaset.
Jul 25 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.