ADDING MULITPLE RECORD in ONE FORM ASP (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


reem_04 -> ADDING MULITPLE RECORD in ONE FORM ASP (10/29/2007 6:50:38)

Hi ALL![:D] I am trying to design inspection form that have different question, two date, corrective active , yes, no and n/a. Forms I wish to design contain all of 30 question plus those filed and insert more than one record. I code I use is the following but it save all of the data in one record in database [:-]

please help me [&o]
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
  MM_editConnection = MM_intraweb_STRING
  MM_editTable = "dbo.dept_safety_Inspection_report_g"
  MM_editRedirectUrl = "new_conf.asp"
  MM_fieldsStr  = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
  MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
  ' create the MM_fields and MM_columns arrays 
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next
  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
  If (Not MM_abortEdit) Then
    ' execute the insert
    Set 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 <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="stylesindex.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
      <table align="center" width="879">
        <tr valign="baseline">
          <td align="center" nowrap="nowrap" class="style2" width="50"><b>Item 
			no.</b></td>
          <td class="style3" width="309" align="center"><b>Item</b></td>
	 <td align="center" width="50"> 
	<p align="center"> 
	<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
	Yes- No -N/A</font></span></td>
	 <td align="center" width="173"> 
	<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
	Corrective Action</font></span></td>	
    <td align="center" width="134"> 
	<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
	Responsibility</font></span></td>
	 <td align="center" width="103"> 
	<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
	Target Date</font></span></td>
	 <td align="center" width="88"> 
	<span style="font-weight: 700">
		 <font face="Verdana" style="font-size: 8pt">Date Completed</font></td>
        </tr>
        <tr>
          <td align="right" nowrap="nowrap" class="style2" width="50" height="75">
			<p align="center">
			<input type="text" name="Item_num" size="4" value="1.1"></td>
          <td class="style3" width="309" height="75">
			<textarea rows="4" name="item" cols="36">q1</textarea></td>
		<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
		<select size="3" name="G_Yes">
			<option selected value="Yes">Yes</option>
			<option value="N/A">N/A</option>
			<option value="No">No</option>
			</select>		</font> </td>
		<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
		<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
		<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
		<input type="text" name="Responsibility" size="20"></font></td>
		<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Target_Date" size="19"></font></td>
		<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Date_Completed" size="16"></font></td>
        	</tr>
        	<tr>
          <td align="right" nowrap="nowrap" class="style2" width="50" height="75">
			<p align="center">
			<input type="text" name="Item_num" size="4" value="1.2"></td>
          <td class="style3" width="309" height="75">
			<textarea rows="4" name="item" cols="36">q2</textarea></td>
		<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
		<select size="3" name="G_Yes">
			<option selected value="Yes">Yes</option>
			<option value="N/A">N/A</option>
			<option value="No">No</option>
			</select>		</font> </td>
		<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
		<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
		<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
		<input type="text" name="Responsibility" size="20"></font></td>
		<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Target_Date" size="19"></font></td>
		<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Date_Completed" size="16"></font></td>
        	</tr>
			<tr>
          <td align="right" nowrap="nowrap" class="style2" width="50" height="75">
			<p align="center">
			<input type="text" name="Item_num" size="4" value="1.3"></td>
          <td class="style3" width="309" height="75">
			<textarea rows="4" name="item" cols="36">q3</textarea></td>
		<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
		<select size="3" name="G_Yes">
			<option selected value="Yes">Yes</option>
			<option value="N/A">N/A</option>
			<option value="No">No</option>
			</select>		</font> </td>
		<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
		<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
		<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
		<input type="text" name="Responsibility" size="20"></font></td>
		<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Target_Date" size="19"></font></td>
		<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Date_Completed" size="16"></font></td>
        	</tr>
        	<tr>
          <td align="right" nowrap="nowrap" class="style2" width="50" height="75">
			<p align="center">
			<input type="text" name="Item_num" size="4" value="1.4"></td>
          <td class="style3" width="309" height="75">
			<textarea rows="4" name="item" cols="36">q4</textarea></td>
		<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
		<select size="3" name="G_Yes">
			<option selected value="Yes">Yes</option>
			<option value="N/A">N/A</option>
			<option value="No">No</option>
			</select>		</font> </td>
		<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
		<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
		<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
		<input type="text" name="Responsibility" size="20"></font></td>
		<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Target_Date" size="19"></font></td>
		<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
			<input type="text" name="Date_Completed" size="16"></font></td>
        	</tr>
        <tr valign="baseline">
          <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td>
        </tr>
        <tr valign="baseline">
          <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div>
			<p align="center"><input type="submit" value="Insert record"/>
          </td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    </td>
  </tr>
</table>
</body>
</html>

thanks alot [8|]




Spooky -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/29/2007 14:07:31)

Why do you need to insert more than one record?




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/29/2007 23:55:36)

Thanks alto Mr. Spooky for you fast responses[:D].
I need at ask user different question (inspection form) that they should answer all of them in different record. [:)][&o]

Item no. Item Yes- No -N/A Label1 Label2 Label3 Label4 Label5
Filed 1 Q1 Filed 2 Filed3 Filed 4 Filed 5 Filed 6 Filed 7
Filed 1 Q2 Filed 2 Filed3 Filed 4 Filed 5 Filed 6 Filed 7
Filed 1 Q3 Filed 2 Filed3 Filed 4 Filed 5 Filed 6 Filed 7
Filed 1 Q4 Filed 2 Filed3 Filed 4 Filed 5 Filed 6 Filed 7

thank all [:D]




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/30/2007 6:32:03)

Your insert statement occurs only once and that is outside the 2nd For..Next loop.

Another thing to check is that MM_i is not initialised after the first For..Next




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/30/2007 6:52:20)

hi again[:D]; i try to use For.. loop ,but each time I but it. It give me an errors. So would you mind tell me where I should place it. More over the data is save in one record in the database.[&:]




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/30/2007 6:58:25)


quote:

ORIGINAL: reem_04

hi again[:D]; i try to use For.. loop ,but each time I but it. It give me an errors. So would you mind tell me where I should place it. More over the data is save in one record in the database.[&:]


Hi
Honestly I don't understand all those Dreamweaver MM stuffs.
I think you should try initialise MM_i=0 before the 2nd For..Next.

If you want to insert more than 1 record, then the instances of the Insert occurring should be more than once. Currently this is the expected result when it is placed outside the loop. It is not recurring.





William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/30/2007 7:08:44)

Try this and we act on the results that are returned:


' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection


If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""

Response.write MM_i 'to test value for MM_i before it goes into the For..Next Loop
MM_i=0

For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert

MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
Next

MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If

End If
%>




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/30/2007 23:56:46)

hi there ! [:D]
thanks mr.William Lee for your help i am using front page and sql server. I try to modify the code as you send me but it give me the following errors could you check.[&o]

ADODB.Command error '800a0bb9' [&o]

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. [&o]

/inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 78
[&o]




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 1:24:19)

quote:

ORIGINAL: reem_04

hi there ! [:D]
thanks mr.William Lee for your help i am using front page and sql server. I try to modify the code as you send me but it give me the following errors could you check.[&o]

ADODB.Command error '800a0bb9' [&o]

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. [&o]

/inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 78
[&o]



What is line 78?
Could you please post the code for this page and please put them inside the [code][/code]




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 1:31:36)

hi there thanks for you fast reply as usual here is your request [:D]
number 78 is ther line where the code giving there errors

[&o]
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_intraweb_STRING
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="stylesindex.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
<table align="center" width="879">
<tr valign="baseline">
<td align="center" nowrap="nowrap" class="style2" width="50"><b>Item
no.</b></td>
<td class="style3" width="309" align="center"><b>Item</b></td>
<td align="center" width="50">
<p align="center">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Yes- No -N/A</font></span></td>
<td align="center" width="173">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Corrective Action</font></span></td>
<td align="center" width="134">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Responsibility</font></span></td>
<td align="center" width="103">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Target Date</font></span></td>
<td align="center" width="88">
<span style="font-weight: 700">
<font face="Verdana" style="font-size: 8pt">Date Completed</font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.1"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q1</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.2"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q2</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.3"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q3</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.4"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q4</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div>
<p align="center"><input type="submit" value="Insert record"/>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
</table>
</body>
</html>




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 1:53:16)

Make sure the include file is correct path.
Are you executing the modified asp page in the same folder as the original asp page?


What is the value of MM_Intraweb_String? This is the value given to MM_EditConnection and giving error? Can you check if this is line 78?

What values are being returned for the 2 response.write statement, if it get that far?




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 3:15:16)

Make sure the include file is correct path
....has been check thanks
Are you executing the modified asp page in the same folder as the original asp page?
.... yes
What is the value of MM_Intraweb_String?
.... is the conection for path of database
This is the value given to
MM_EditConnection and giving error? Can you check if this is line 78?
.... yes this the line where it give me error
MM_editCmd.ActiveConnection = MM_editConnection

What values are being returned for the 2 response.write statement, if it get that far?
.... i am using fornt page for the asp code i don't know how to track the code in it but it give me this error

ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 78




[/quote]




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 3:21:37)

Do you have adovbs.inc as include in your project?

This is a file of ADO constants.




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 3:27:41)


Do you have adovbs.inc as include in your project?
..no i don't have file in the form with this ext. i only have include file for connection
<!--#include file="../../Connections/intraweb.asp" -->
..

This is a file of ADO constants.
[/quote]




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 3:39:28)


quote:

ORIGINAL: reem_04


What is the value of MM_Intraweb_String?
.... is the conection for path of database
This is the value given to
MM_EditConnection and giving error? Can you check if this is line 78?
.... yes this the line where it give me error
MM_editCmd.ActiveConnection = MM_editConnection




the clue is in the connection. Are you able to provide the contents of that include file but censor the password and usrname and paths?




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 5:33:50)

OK, it seems if you want to execute the INSERT multiple times, you really need to create and establish a Connection to your db. The original script is good for ONE specific, single query.


I recommend the following amendments to my previous changes:

Put these inside the <%...%> of the include file, at the end

set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString=MM_intraweb_String
conn.Open



Then comment out the line MM_editConnection=MM_intraweb_STRING as conn will be used instead.

Next change line 78 to MM_editCmd.ActiveConnection=conn

Finally, change MM_editCmd.ActiveConnection.Close to conn.close. This is right at the end, when the code exits the For..Next loop.

For good practice, set all Connections to Nothing at the end.
Set conn=Nothing


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
' *** MM_editConnection = MM_intraweb_STRING ---comment out this line
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = conn '*** MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
conn.Close
Set conn=Nothing
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>





reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 6:16:58)

hi again thanks alot [:D]

(the code that you send to me before it work ,but it repated recod 7 times and all of the data in differet recored repated 7 times )

sorry i recivie this error but the [&o]

ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 77


here is the code [&o]

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = conn '*** MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection

MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
conn.Close
Set conn=Nothing
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="stylesindex.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
<table align="center" width="879">
<tr valign="baseline">
<td align="center" nowrap="nowrap" class="style2" width="50"><b>Item
no.</b></td>
<td class="style3" width="309" align="center"><b>Item</b></td>
<td align="center" width="50">
<p align="center">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Yes- No -N/A</font></span></td>
<td align="center" width="173">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Corrective Action</font></span></td>
<td align="center" width="134">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Responsibility</font></span></td>
<td align="center" width="103">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Target Date</font></span></td>
<td align="center" width="88">
<span style="font-weight: 700">
<font face="Verdana" style="font-size: 8pt">Date Completed</font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.1"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q1</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.2"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q2</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.3"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q3</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.4"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q4</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div>
<p align="center"><input type="submit" value="Insert record"/>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
</table>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString=MM_intraweb_String
conn.Open
%>
</body>
</html>





William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 6:24:45)


quote:

ORIGINAL: reem_04


</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
</table>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString=MM_intraweb_String
conn.Open
%>
</body>
</html>



No,no...I don't mean put them here.
You should put them inside the /connections/intraweb.asp include file [:D]

Put them after the MM_intraweb_STRING definition line.




reem_04 -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 7:04:13)

hi again [:D]this is the error i recivie[&o]
14insert into dbo.dept_safety_Inspection_report_g (Item) values ('q1, q2, q3, q4')
ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 122
this is the code

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb_new.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = conn '*** MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
conn.Close
Set conn=Nothing
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="stylesindex.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
<table align="center" width="879">
<tr valign="baseline">
<td align="center" nowrap="nowrap" class="style2" width="50"><b>Item
no.</b></td>
<td class="style3" width="309" align="center"><b>Item</b></td>
<td align="center" width="50">
<p align="center">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Yes- No -N/A</font></span></td>
<td align="center" width="173">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Corrective Action</font></span></td>
<td align="center" width="134">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Responsibility</font></span></td>
<td align="center" width="103">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Target Date</font></span></td>
<td align="center" width="88">
<span style="font-weight: 700">
<font face="Verdana" style="font-size: 8pt">Date Completed</font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.1"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q1</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.2"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q2</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.3"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q3</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.4"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q4</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div>
<p align="center"><input type="submit" value="Insert record"/>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
</table>
</body>
</html>





William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 7:24:56)



You should be using the code below.
quote:




<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
' *** MM_editConnection = MM_intraweb_STRING ---comment out this line
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = conn '*** MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
conn.Close
Set conn=Nothing
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>







William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (10/31/2007 8:51:54)


Sorry I missed out the part about the record repeating 7 times. You'll have to initialise these 2 after executing the Insert statement.

MM_tableValues = ""
MM_dbValues = ""




William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (11/1/2007 4:43:10)


OK, I have repositioned these 2 so that they are initialised everytime the INSERT statement is executed and the code goes into Next MM_i

MM_tableValues = ""
MM_dbValues = ""


quote:

ORIGINAL: William Lee



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i




MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
' *** MM_editConnection = MM_intraweb_STRING ---comment out this line
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"

MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If
End If


End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = conn '*** MM_editConnection

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
'**** this line is moved *** MM_tableValues = ""
'**** this line is moved **** MM_dbValues = ""

Response.write MM_i
' **** to test value for MM_i before it goes into the For..Next Loop
MM_i=0


For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2

MM_tableValues = "" '****moved to here
MM_dbValues = "" '****moved to here


MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

Response.write MM_editQuery ' see what the SQL statement is like

If (Not MM_abortEdit) Then
' execute the insert
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
End if
next
conn.Close
Set conn=Nothing
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

%>









William Lee -> RE: ADDING MULITPLE RECORD in ONE FORM ASP (11/4/2007 9:26:37)

Any updates?




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.15625