Print Page | Close Window

Define Unchecked Value in a Form

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=28427
Printed Date: 29 March 2026 at 12:51am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Define Unchecked Value in a Form
Posted By: kennywhite
Subject: Define Unchecked Value in a Form
Date Posted: 15 March 2010 at 3:18pm
Hello.

I have a form with a checkbox. When the box is checked the form submits properly and all is good. When it is not checked I get this error message.

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

Here is the code for the check box:

<input name="completed" type="checkbox" id="completed" checked value="true">

The page that the data is posted to looks like this.

<% 'Dimension variables
Dim adoCon           'Holds the Database Connection Object 
Dim rsUpdateEntry    'Holds the recordset for the record to be updated
Dim strSQL           'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated


'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the recordset with the SQL query 
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset







rsUpdateEntry.Fields("Completed") = Request.Form("Completed")






'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

'Return to the update select page in case another record needs deleting
Response.Redirect "manage.asp"
%> 

Is there anything that I could easily change to fix this problem?


Thanks!



Replies:
Posted By: Scotty32
Date Posted: 16 March 2010 at 1:43pm

I wouldnt recommend entering the form data direct like that.

Add this to your form gathering section:
blnFormCompleted = CBool(Request.Form("Completed"))

Then change the update part like so:
rsUpdateEntry.Fields("Completed") = blnFormCompleted


-------------
S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins

For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .


Posted By: kennywhite
Date Posted: 16 March 2010 at 5:00pm
I was unable to get that to work. I think I misunderstood where to place the code. Would you mind to point out the proper place for me?

Here is the entire code for the form page:

<%
'Dimension variables
Dim adoCon          'Holds the Database Connection Object
Dim rsProject    'Holds the recordset for the records in the database
Dim strSQL           'Holds the SQL query for the database
Dim lngRecordNo    'Holds the record number to be updated
           'Read in the record number to be updated
lngRecordNo = CLng(Request.QueryString("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsProject = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Open the recordset with the SQL query
rsProject.Open strSQL, adoCon

thisContent = rsProject("Notes")
thisContent = replace(thisContent,"'","\'")
%>

<form name="F1" id="F1" method="post" action="update_entry2.asp">
<div id="form">
<table width="980">
<tr>
<td width="96">
<b>
Project Title:
</b>
</td><td width="894">

<input type="text" name="ProjectTitle" style="width:99%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<% = rsProject("ProjectTitle") %>"> </td>
</tr></table>

<table width="980">
<tr>
<td width="176">
<b>
Targeted Completion Date:
</b>
</td><td width="690">
<input type="text" name="TargetDate" style="width:10%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"value="<% = rsProject("TargetDate") %>"> </td>

<td width="1">
<b>
Priority:
</td><td width="9">
<input type="text" name="Priority" style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"value="<% = rsProject("Priority") %>"> </td></tr></table>

<table>
<tr>
<td>
<b>
Details:</td> </tr></table>

<!-- #INCLUDE file="includes/FCKeditor/fckeditor.asp" -->
<%
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = "includes/FCKeditor/"
oFCKeditor.Create "notes"
%>
<script language="javascript" type="text/javascript">
<!--
window.onload = function()
{
document.F1.notes.value= ' <%=thisContent%> ' ;
}
-->
</script>
</td></tr></table><table width="980"><tr><td width="20">
<b>
Submitted By:
</td><td width="110">
<input type="text" name="SubmittedBy"style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<% = rsProject("SubmittedBy") %>">
</td>
<td width="10">
<b>
On:
</td><td valign="center" width="100">
<input type="text" name="PostedDate" style="width:70%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;" value="<% = rsProject("PostedDate") %>">
</td>
<td width="130"> Project Complete <input name="completed" type="checkbox" id="completed" value="true" checked>
</td>
<td width="20">
<b>
Completeded By:
</td><td width="115">

<input type="text" name="CompletedBy"style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"> </td>
<td width="10">
<b>
On:
</td><td valign="center" width="70">
<input type="text" name="CompletedDate" style="width:95%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;">
</td>

<td valign="bottom" align="right" width="128">

<input type="hidden" name="ID" value="<% = rsProject("ID") %>">

 <br> <input type="submit" name="Submit" value="Submit">
</form>
</td>
</tr></table>
</div>
</form>
<!-- End form code -->
</body>
</html>
<%
'Reset server objects
rsProject.Close
Set rsProject = Nothing
Set adoCon = Nothing
%>






And here is the complete page where the data is processed.







[code]

<% 'Dimension variables
Dim adoCon           'Holds the Database Connection Object
Dim rsUpdateEntry    'Holds the recordset for the record to be updated
Dim strSQL           'Holds the SQL query to query the database
Dim lngRecordNo      'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the recordset with the SQL query
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset

rsUpdateEntry.Fields("ProjectTitle") = Request.Form("ProjectTitle")
rsUpdateEntry.Fields("TargetDate") = Request.Form("TargetDate")

rsUpdateEntry.Fields("SubmittedBy") = Request.Form("SubmittedBy")

rsUpdateEntry.Fields("PostedDate") = Request.Form("PostedDate")

rsUpdateEntry.Fields("Priority") = Request.Form("Priority")

rsUpdateEntry.Fields("Notes") = Request.Form("Notes")

rsUpdateEntry.Fields("Completed") = Request.Form("Completed")

rsUpdateEntry.Fields("CompletedBy") = Request.Form("CompletedBy")
rsUpdateEntry.Fields("CompletedDate") = Request.Form("CompletedDate")

'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdate


Posted By: Scotty32
Date Posted: 20 March 2010 at 12:41pm
To be perfectly honest with you, it is hard to read through your entire page of code looking for the relevant parts.


As I said, you should avoid entering form values straight into the database.

I would recommend getting into the habit of structuring your pages so that you grab the values from the form, then enter into the database.

So you would add/alter the following in red:

lngRecordNo = CLng(Request.Form("ID"))
blnFormCompleted = CBool(Request.Form("Completed"))



rsUpdateEntry.Fields("Notes") = Request.Form("Notes")
rsUpdateEntry.Fields("Completed") = blnFormCompleted



This allows you to error check the entered fields, eg if a field is empty or to big you can display an error message instead of code error.

rsUpdateEntry.Fields("Completed") = Request.Form("Completed")


-------------
S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins

For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net