Hi
I found a piece of code on the internet that seems to do what I want but I am not sure how to configure it so that it will allow me to edit the following
database: stocks
fields: txtcompanyname,txtsymbol,txtpurdate,txttradedate,txtshares,txtcost,txtvalue
I found this code at:http://www.drdev.net/article11.asp
here is the code it is only one page
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request("Submit") <> "" Then
intRecIDs = Replace(Request("hidRecIDs"), "*", "") ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
arrRecIDs = Split(intRecIDs, ", ") ' Create an array, wich will contain just the IDs of the records we need to update
For i = 0 to Ubound(arrRecIDs) ' Loop trough the array
strText = Replace(Request("txtText" & arrRecIDs(i)), "'", "''")
intNum = Replace(Request("txtNum" & arrRecIDs(i)), "'", "''")
set commUpdate = Server.CreateObject("ADODB.Command")
commUpdate.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TestDB.mdb") & ";Persist Security Info=False"
commUpdate.CommandText = "UPDATE TestTable SET RecText = '" & strText & "', RecNum = " & intNum & " WHERE RecID = " & arrRecIDs(i)
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
Next
strMessage = i & " Records Updated"
Response.Redirect("MultiUpdateDemo.asp?Message=" & strMessage)
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TestDB.mdb") & ";Persist Security Info=False"
Recordset1.Source = "SELECT RecID, RecText, RecNum FROM TestTable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Update Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
// When the value in a textfield is changed, notice the onChange="RecUpdate('<%= intRecID %>')"
// on each of the textfields, the value of the Record ID associated with that field
// is passed to the RecUpdate function. First the value is surounded with 2 asterisks e.g. *6*
// This is so that *1* can be distinguished from *10*, *11* etc.
function RecUpdate(RecID){
var ThisID = "*" + (RecID) + "*"
if (document.form1.hidRecIDs.value == ""){ // If the hidden field is empty
document.form1.hidRecIDs.value = (ThisID) // Store the value in the hidden field (hidRecIDs) as it is.
}
if (document.form1.hidRecIDs.value != ""){ // If the hidden field isn't empty
var str = document.form1.hidRecIDs.value; // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID); // Search str to see if this RecID is allready in it.
if (pos == -1) { // If the position returned is -1 it isn't allredy in there,
document.form1.hidRecIDs.value = document.form1.hidRecIDs.value + ", " + (ThisID)
} // so add ", " and this ID to what is already in hidRecIDs
} // to create a list like this *2*, *5*, *8* etc.
}
//-->
</script>
</head>
<body>
<font size="2" face="Arial, Helvetica, sans-serif"><%= Request.QueryString("Message") %></font>
<br>
<form name="form1" method="post" action="MultiUpdateDemo.asp">
<table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#666699">
<tr>
<td><table width="500" border="0" cellpadding="0" cellspacing="6" bgcolor="#EEEFF2">
<tr>
<td width="37"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecID</font></strong></td>
<td width="217"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecText</font></strong></td>
<td width="226"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecNum</font></strong></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<% intRecID =(Recordset1.Fields.Item("RecID").Value) ' Store the current RecordID in a variable %>
<tr>
<td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><%= intRecID %><input name="hidRecID<%= intRecID %>" type="hidden" value="<%= intRecID %>" size="5"></font></td>
<td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><input name="txtText<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecText").Value)%>" size="20"></font></td>
<td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><input name="txtNum<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecNum").Value)%>" size="20"></font></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table></td>
</tr>
</table>
<br>
<input name="hidRecIDs" type="text" size="40">
<font size="2" face="Arial, Helvetica, sans-serif"><=== This would be hidden</font><br>
<br>
<font size="2" face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Update">
</font>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>