|
jgerding13 -> RE: Update multiple records (4/1/2008 17:04:15)
|
Ok thanks I think I am closer, here is my final code below But what ever value I put in Jan08 box gets replicated to all months <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request("Submit") <> "" Then
intIDs = Replace(Request("hidIDs"), "*", "") ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
arrIDs = Split(intIDs, ", ") ' Create an array, wich will contain just the IDs of the records we need to update
For i = 0 to Ubound(arrIDs) ' Loop trough the array
strText = Replace(Request("txtText" & arrIDs(i)), "'", "''")
intNum = Replace(Request("txtNum" & arrIDs(i)), "'", "''")
set commUpdate = Server.CreateObject("ADODB.Command")
commUpdate.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../machines.mdb") & ";Persist Security Info=False"
commUpdate.CommandText = "UPDATE Beverage SET Jan08 = " & strText & ",Feb08 = " & strText & ",March08 = " & strText & ",Qtr_1_2008 = " & strText & ",Apr08 = " & strText & ",May08 = " & strText & ",June08 = " & strText & ",Qtr_2_2008 = " & strText & ",July08 = " & strText & ",Aug08 = " & strText & ",Sept08 = " & strText & ",Qtr_3_2008 = " & strText & ",Oct_08 = " & strText & ",Nov_08 = " & strText & ",Dec_08 = " & strText & ",Qtr_4_2008 = " & strText & ",Total = " & strText & " WHERE ID = " & arrIDs(i)
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
Next
strMessage = i & " Records Updated"
Response.Redirect("testupdate.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("../machines.mdb") & ";Persist Security Info=False"
Recordset1.Source = "SELECT * FROM Beverage"
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('<%= intID %>')"
// 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(ID){
var ThisID = "*" + (ID) + "*"
if (document.form1.hidIDs.value == ""){ // If the hidden field is empty
document.form1.hidIDs.value = (ThisID) // Store the value in the hidden field (hidIDs) as it is.
}
if (document.form1.hidIDs.value != ""){ // If the hidden field isn't empty
var str = document.form1.hidIDs.value; // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID); // Search str to see if this ID is allready in it.
if (pos == -1) { // If the position returned is -1 it isn't allredy in there,
document.form1.hidIDs.value = document.form1.hidIDs.value + ", " + (ThisID)
} // so add ", " and this ID to what is already in hidIDs
} // 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="testupdate.asp">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#666699" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="973">
<table width="1254" border="0" cellpadding="0" cellspacing="1" bgcolor="#EEEFF2" style="border-collapse: collapse" bordercolor="#111111" height="54">
<tr>
<td width="11" nowrap height="24"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">ID</font></strong></td>
<td width="98" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Cust
No</font></strong></td>
<td width="231" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Name</font></strong></td>
<td width="35" nowrap height="24"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">Jan08</font></strong></td>
<td width="35" nowrap height="24"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">Feb08</font></strong></td>
<td width="36" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Mar08</font></strong></td>
<td width="33" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">1st
QTR</font></strong></td>
<td width="33" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Apr08</font></strong></td>
<td width="37" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">May08</font></strong></td>
<td width="43" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">
June08</font></strong></td>
<td width="34" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">2nd
Qtr</font></strong></td>
<td width="38" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">
July08</font></strong></td>
<td width="37" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Aug08</font></strong></td>
<td width="40" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">
Sept08</font></strong></td>
<td width="34" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">3rd
Qtr</font></strong></td>
<td width="34" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Oct08</font></strong></td>
<td width="38" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Nov08</font></strong></td>
<td width="37" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Dec08</font></strong></td>
<td width="34" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">4th
Qtr</font></strong></td>
<td width="431" nowrap height="24"><strong>
<font face="Arial, Helvetica, sans-serif" size="1" color="#333333">Total</font></strong></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<% intID =(Recordset1.Fields.Item("ID").Value) ' Store the current RecordID in a variable %>
<tr>
<td nowrap width="11" height="12"><font size="1" face="Arial, Helvetica, sans-serif"><%= intID %></font><font size="1" face="Arial"><input name="hidID<%= intID %>" type="hidden" value="<%= intID %>" size="5"></font></td>
<td nowrap width="98" valign="bottom" height="12"><font size="1" face="Arial"><%=(Recordset1.Fields.Item("Cust_No").Value)%><p></td>
<td nowrap width="231" height="12"><font size="1" face="Arial"><%=(Recordset1.Fields.Item("Customer_Name").Value)%></td>
<td nowrap width="35" height="12"><font size="1" face="Arial">
<input name="txtText<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Jan08").Value)%>" size="3"></font></td>
<td nowrap width="35" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>1" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Feb08").Value)%>" size="3"></font></td>
<td nowrap width="36" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("March08").Value)%>" size="3"></font></td>
<td nowrap width="33" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Qtr_1_2008").Value)%>" size="3"></font></td>
<td nowrap width="33" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Apr08").Value)%>" size="3"></font></td>
<td nowrap width="37" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("May08").Value)%>" size="3"></font></td>
<td nowrap width="43" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("June08").Value)%>" size="3"></font></td>
<td nowrap width="34" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Qtr_2_2008").Value)%>" size="3"></font></td>
<td nowrap width="38" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("July08").Value)%>" size="3"></font></td>
<td nowrap width="37" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Aug08").Value)%>" size="3"></font></td>
<td nowrap width="40" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Sept08").Value)%>" size="3"></font></td>
<td nowrap width="34" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Qtr_3_2008").Value)%>" size="3"></font></td>
<td nowrap width="34" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Oct_08").Value)%>" size="3"></font></td>
<td nowrap width="38" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Nov_08").Value)%>" size="3"></font></td>
<td nowrap width="37" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Dec_08").Value)%>" size="3"></font></td>
<td nowrap width="34" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Qtr_4_2008").Value)%>" size="3"></font></td>
<td nowrap width="431" height="12"><font size="1" face="Arial">
<input name="txtNum<%= intID %>" type="text" onChange="RecUpdate('<%= intID %>')" value="<%=(Recordset1.Fields.Item("Total").Value)%>" size="3"></font></td>
</tr>
<tr>
<td nowrap width="1368" height="15" colspan="20">
<hr color="#000000" size="1" noshade></td>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</tr>
</table></td>
</tr>
</table>
<br>
<input name="hidIDs" 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
%>
|
|
|
|