Check Box Error

Results 1 to 3 of 3

Thread: Check Box Error

  1. #1
    Join Date
    Dec 1969

    Default Check Box Error

    If I check my check box on the asp form it submits to the Access Database fine, however if I leave the checkbox blank and fill the other fields out I get this error message:<BR>Microsoft OLE DB Provider for ODBC Drivers error &#039;80040e21&#039; <BR><BR>Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. <BR><BR>timesheets/ets.asp, line 61 <BR><BR><BR>The value in the checkbox is "1", and I&#039;ve tried yes/no and true/false. the main part of the code is here:<BR><BR><BR>DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("EmployeeTimeSheets.mdb") & ";"<BR><BR><BR>Set objRecordset = Server.CreateObject("ADODB.Recordset")<BR>objRecor dset.Open "tblMyTable", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable<BR><BR>objRecordset.Fields("MondayOvert ime") = Request.Form("txtMondayOvertime")<BR>objRecordset. Fields("CheckBox1") = Request.Form("Checkbox")<BR><BR>Any help much appreciated.<BR><BR><BR><BR><BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Check Box Error

    objRecordset.Fields("CheckBox1") = len(Request.Form("Checkbox"))<BR>

  3. #3
    Join Date
    Dec 1969

    Default Well, for Access...

    ...since checkboxes in Access are *ACTUALLY* True/False DB fields, it&#039;s better to use this:<BR><BR>&#060;%<BR>objRecordset("checkbox1") = ( Request("checkbox1") &#060;&#062; "" )<BR>%&#062;<BR><BR>Why?<BR><BR>Because <BR><BR>(a) an UNCHECKED checkbox has NO VALUE WHATSOEVER in the ASP page that the form submits to. Which explains why you were getting the errors. You were passing NULL to your checkbox fields.<BR><BR>(b) The code there is a kind of "shorthand" for this:<BR> If ( Request("checkbox1") &#060;&#062; "" ) Then temp = True Else temp = False<BR> objRecordset("Checkbox1") = temp<BR><BR><BR>If you think about it, what *is* the value of <BR> ( Request("checkbox1") &#060;&#062; "" )<BR>when the box is checeked? Since it is, indeed, &#060;&#062; to "" then the value is true. And the value when it is unchecked? Well it will be = to "", so &#060;&#062; "" will give a false answer, yes?<BR><BR>So we didn&#039;t need the IF...THEN...ELSE, did we? We could have simply coded:<BR> temp = (Request("checkbox1") &#060;&#062; "")<BR> objRecordset("Checkbox1") = temp<BR>But then what do we need temp for any more? So, simply:<BR> objRecordset("Checkbox1") = (Request("checkbox1") &#060;&#062; "")<BR><BR>**********<BR><BR>Lars&#039; answer is appropriate for SQL Server, which doesn&#039;t have True/False fields. Instead, with SQL Server you would just use a "tinyint" field and give it a value of 1 [or any non-zero number] or 0 (instead of True or False).<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts