Please may I know what error Microsoft JET Database Engine error '80040e10 in classic ASP with ms access

206 Views Asked by At

Can anyone please help me resolve this problem? After checking that recordset is not empty with if(!Question.eof){...} I encountered another error in my code. Error on line 166, as shown in code below. Will appreciate it if someone can please point me in the right direction. Thank you.

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include Virtual="Connections/Recipe.asp" -->

<%
if (String(Request("Delete"))!="undefined") {
%>


<%

if(String(Request.Form("MM_recordId") ) != "undefined"){ 
DeleteQuestion__IDParam = String(Request.Form("MM_recordId") );}

%>

<%

var DeleteQuestion = Server.CreateObject("ADODB.Command");
DeleteQuestion.ActiveConnection = MM_Recipe_STRING;
DeleteQuestion.CommandText = "DELETE FROM SurveyQuestions WHERE 
QuestionID = "+ DeleteQuestion__IDParam.replace(/'/g, "''") + "";
DeleteQuestion.CommandType = 1;
DeleteQuestion.CommandTimeout = 0;
DeleteQuestion.Prepared = true;
DeleteQuestion.Execute();

%>
<%

var RemoveOrphanResults = Server.CreateObject("ADODB.Command");
RemoveOrphanResults.ActiveConnection = MM_Recipe_STRING;
RemoveOrphanResults.CommandText = "RemoveOrphanResults  ";
RemoveOrphanResults.CommandType = 4;
RemoveOrphanResults.CommandTimeout = 0;
RemoveOrphanResults.Prepared = true;
RemoveOrphanResults.Execute();

%>

<%
Response.Redirect("edit_survey.asp");
}
%>


<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Request.QueryString;
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Update Record: set variables

if (String(Request("MM_update")) == "EditSurveyQuestion" &&
String(Request("MM_recordId")) != "undefined") {

var MM_editConnection = MM_Recipe_STRING;
var MM_editTable  = "SurveyQuestions";
var MM_editColumn = "QuestionID";
var MM_recordId = "" + Request.Form("MM_recordId") + "";
var MM_editRedirectUrl = "edit_survey.asp";
var MM_fieldsStr = 
"QuestionType|value|QuestionText|value|AnswerText|value";
var MM_columnsStr = "QuestionType|none,none,
   NULL|QuestionText|',none,''|QuestionAnswers|',
none,''";

// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");

// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}

// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && 
Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == 
-1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Update Record: construct a sql update statement and execute it

if (String(Request("MM_update")) != "undefined" &&
String(Request("MM_recordId")) != "undefined") {

// create the sql update statement
MM_editQuery = "update " + MM_editTable + " set ";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim =    (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal =   (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
  formVal = emptyVal;
} else {
  if (altVal != "") {
    formVal = altVal;
  } else if (delim == "'") { // escape quotes
    formVal = "'" + formVal.replace(/'/g,"''") + "'";
  } else {
    formVal = delim + formVal + delim;
  }
}
MM_editQuery += ((i != 0) ? "," : "") + MM_columns[i] + " = " + 
formVal;
}
MM_editQuery += " where " + MM_editColumn + " = " + MM_recordId;

if (!MM_abortEdit) {
// execute the update
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {
  Response.Redirect(MM_editRedirectUrl);
}
}

}
%>

<%
var Question__MMColParam = "1";
if (String(Request.QueryString("ID")) != "undefined" && 
String(Request.QueryString("ID")) != "") { 
Question__MMColParam = String(Request.QueryString("ID"));
}
%>
<%
var Question = Server.CreateObject("ADODB.Recordset");
Question.ActiveConnection = MM_Recipe_STRING;
Question.Source = "SELECT * FROM SurveyQuestions WHERE QuestionID = 
"+ Question__MMColParam.replace(/'/g, "''") + "";
Question.CursorType = 0;
Question.CursorLocation = 2;
Question.LockType = 1;
Question.Open();
var Question_numRows = 0;
%>
<%
var Survey__IDParam = "0";
if (!Question.eof) {
if (String(Question.Fields("QuestionSurvey")) != "undefined" && 
String(Question.Fields("QuestionSurvey")) != "") { 
Survey__IDParam = String(Question.Fields("QuestionSurvey"));
}
}
%>
<%
var Survey = Server.CreateObject("ADODB.Recordset");
Survey.ActiveConnection = MM_Recipe_STRING;
Survey.Source = "SELECT *  FROM Surveys  WHERE QuestionID = "+ 
Survey__IDParam.replace(/'/g, "''") + "";
Survey.CursorType = 0;
Survey.CursorLocation = 2;
Survey.LockType = 1;

This is line 166 below. (Survey.open();)
Survey.Open();

var Survey_numRows = 0;
%>

The below code is mostly HTML, with a few dynamic data from recordset.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Survey</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859- 
1">
<link href="../../css/workgroup.css" rel="stylesheet" 
type="text/css">

</head>

<body>
<div id="header">
<img src="../../images/workgroup/logo_leafmedia.gif" width="367" 
height="84"></div>
<div id="topnav">&nbsp; <span class="buttonselected" 
id="leftbutton">SURVEY BUILDER</span> <span class="buttons" 
id="leftcenterbutton"><a 
href="../../TimeCards/TimeCards_JS/view_timecards.asp">TIME CARDS</a> 
</span> <span class="buttons" id="rightcenterbutton"><a 
href="../../Journal/Journal_JS/manage_journals.asp">JOURNAL</a> 
</span>  <span class="buttons" id="rightbutton"><a 
href="../../MailMerge/MailMerge_JS/mailbox.asp">MAIL MERGE</a></span> 
</div>
<div id="separator"></div>
<div id="wrapper">
<table width="100%" border="0" cellpadding="0" cellspacing="0" 
id="midtable" >
<tr id="contentrow">
  <td>
    <table width="190" border="1" cellpadding="2" cellspacing="0" 
id="navtable">
      <tr>
        <td class="navigation">Survey Builder</td>
      </tr>
      <tr>
        <td class="nav"><a href="survey_manager.asp">Survey 
Manager</a></td>
      </tr>
      <tr>
        <td class="nav"><a href="add_survey.asp">New Survey</a></td>
      </tr>
    </table>
  <img src="../../images/workgroup/breakthrough_surveybuilder.gif" 
alt="abstract layout image" width="245" height="248"></td>
  <!-- InstanceBeginEditable name="Content" --><td width="100%" 
id="contentcell"><table width="100%" border="0" cellspacing="0" 
cellpadding="0">
    <tr>
      <td height="25" bgcolor="#FF9900">&nbsp;</td>
    </tr>
    <tr>
      <td height="40"><table width="100%" class="layoutTable" 
border="0" cellpadding="6" cellspacing="0">
          <tr>
            <td width="300" align="center" valign="bottom" 
bgcolor="#FFCC99" class="pageHeader">EDIT
              SURVEY QUESTION</td>
            <td bgcolor="#FF9900">&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td><form action="<%=MM_editAction%>" method="POST" 
name="EditSurveyQuestion" id="EditSurveyQuestion">
        <table width="100%" border="0" cellspacing="0" 
cellpadding="6">
          <tr>
            <td>&nbsp;</td>
            <td nowrap class="formTitle">Survey Name</td>
            <td class="formField"><%= 
(Survey.Fields.Item("SurveyName").Value)%></td>
          </tr>
          <tr>
            <td width="25">&nbsp;</td>
            <td colspan="2" class="subHeader">&nbsp;</td>
          </tr>
          <tr>
            <td width="25">&nbsp;</td>
            <td nowrap class="formTitle">Question Type</td>
            <td class="formField"><select name="QuestionType">
            <option value="1" selected <%=((1 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Text 
(50 char)</option>
            <option value="2" <%=((2 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Essay 
(Textarea)</option>
            <option value="3" <%=((3 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Choice 
- One Answer (Radio)</option>
            <option value="4" <%=((4 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Choice 
- Multiple Answers (Multi-select)</option>
            <option value="5" <%=((5 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Choice 
- One Answer (Drop down)</option>
            <option value="6" <%=((6 == 
(Question.Fields.Item("QuestionType").Value))?"SELECTED":"")%>>Yes or 
No (Checkbox)</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td colspan="2" class="subHeader">&nbsp;</td>
          </tr>
          <tr>
            <td width="25">&nbsp;</td>
            <td class="formTitle">Question</td>
            <td class="formField"><input name="QuestionText" 
type="text" id="QuestionText" value="<%= 
(Question.Fields.Item("QuestionText").Value)%>" size="60">
            </td>
          </tr>
          <tr>
            <td width="25">&nbsp;</td>
            <td valign="top" class="formTitle">Answer</td>
            <td class="formField"><textarea name="AnswerText" 
cols="55" rows="5" wrap="VIRTUAL" id="AnswerText"><%= 
(Question.Fields.Item("QuestionAnswers").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td valign="top" class="formTitle">&nbsp;</td>
            <td class="smallText">Note: each answer will appear on 
separate
              lines in the survey; type additional answer options on 
new
              lines. For text and textarea type questions this field 
becomes
              the default value.</td>
          </tr>
          <tr>
            <td width="25">&nbsp;</td>
            <td class="formTitle">&nbsp;</td>
            <td class="formField"><input name="SaveQuestion" 
type="submit" id="SaveQuestion" value="Save">
&nbsp;
    <input name="Delete" type="submit" id="Delete" value="Delete">
&nbsp;
    <input name="Reset" type="reset" id="Reset" value="Reset">
            </td>
          </tr>
        </table>
      
                    <input type="hidden" name="MM_update" 
value="EditSurveyQuestion">
        <input type="hidden" name="MM_recordId" value="<%= 
Question.Fields.Item("QuestionID").Value %>">
      </form>
        </td>
    </tr>
  </table>
    </td>
  <!-- InstanceEndEditable -->
  <td width="44" id="spacercell"><img 
src="../../images/workgroup/spacer.gif" width="44" height="10"></td>
</tr>
</table>
</div>
<div id="footer"><img src="../../images/workgroup/footer_left.gif"> 
</div>
</body>
<!-- InstanceEnd --></html>
<%
Question.Close();
%>
<%
Survey.Close();
%>
1

There are 1 best solutions below

1
John On

Error 8004e10 is 'No value given for one or more required parameters.' so I'm going to guess that Survey__IDParam is blank and no value is being passed into the query which comes shortly before line 166, ie:

Survey.Source = "SELECT *  FROM Surveys  WHERE QuestionID = "+ 
Survey__IDParam.replace(/'/g, "''") + "";.  

You could test this theory by putting in a hard coded value for QuestionID.

As some have suggested in the comments, using Dreamweaver to learn Classic ASP is not a good idea, it produces awful, bloated code. For example QuestionID looks like it might be the primary key field of a table in your JET database. If it is then it's going to be a numeric field and there's no need to use the replace function to change a single quote into a pair of single quotes, but Dreamweaver adds it to cover all bases.

I love Classic ASP but it's very "legacy" these days so if you're doing this to teach yourself to code you might want to think about learning something more popular today. Also, you're using Javascript as your server side language. Most Classic ASP applications use VBScript, and most of the coding examples you'll find on this site and elsewhere use VBScript, so while ASP with Javascript is a perfectly valid technology to use, it's a niche of a niche.