View Full Version : Need value for 'unchecked' checkbox

03-22-2007, 01:05 AM
Hello all. I have the following line of code to update a value in the DB, but when a value of a checkbox is checked and I change it to unchecked, I get the following error becaues there is no value coming from the checkbox.

Here is the SQL statement:

Active = Request.Form("cbxActive")

UPDATE tblEquipment SET EqNum = '" & EqNum & "', EqDesc = '" & EqDesc & "', Active = '" & Active & "' WHERE ID = " & ID

Here is the error I am getting:

Microsoft JET Database Engine error '80040e07'

Data type mismatch in criteria expression.

/Equipment/Eq_AddEdit2.asp, line 81

Here is the SQL statement in action:

UPDATE tblEquipment SET EqNum = 'DZR-0001', EqDesc = 'Dozer', Active = '' WHERE ID = 12

How can I get a value for the unchecked checkbox?

Thanks in advance,


03-22-2007, 10:20 AM
As far as i know, the unchecked check box is not in the Request.Form collection. When you are accessing this element in the collection, the element is entered into the collection with an empty value. So testing for this empty value should be enough to see if the box is checked or not. If the box is checked, you receive the value which is defined in the html.

03-22-2007, 01:24 PM
I think you have to check which value of checkbox is coming by tracking the query...

03-23-2007, 06:52 AM
Thank you both for your input. I know when it is checked, the value = 'True', so I guess that I could just put an:

Active = Request.Form("cbxActive")

If Active = "" Then
Active = 0
End If

I will have to check it when I get back into town.

Thanks again,


04-18-2007, 04:40 PM
There are different ways you can check this. It depends on how your database is setup.

If you have a table that sets checked boxes to active then what you can do is set all the fields to false, then update the fields to true that were checked.


If Len(Request.Form)>0 Then
id = Request.Form("id")

sql = "UPDATE checkboxes SET active = False"

Set updateAll = Server.CreateObject("ADODB.Command")
updateAll.ActiveConnection = MM_TEST_STRING
updateAll.CommandText = sql

If Len(id) > 0 Then
sql = "UPDATE checkboxes SET active = True WHERE id IN (" & id & ")"

Set updateChecked = Server.CreateObject("ADODB.Command")
updateChecked.ActiveConnection = MM_TEST_STRING
updateChecked.CommandText = sql

End If
msg = "Records Updated<br>" & sql
End If

04-18-2007, 04:47 PM
Thank you for your effort. Actually, the following code worked perfectly. I know it probably isn't the most professional way of doing it, but it is quick and simple.

Active = Request.Form("cbxActive")

If Active = "" Then
Active = 0
End If

Thanks again,


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum