Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I relate the checkbox to an access database

Status
Not open for further replies.

caballeros

IS-IT--Management
Dec 12, 2000
5
US
Please look at the following code, I'm trying to present a grid type form when a user clicks on the checkbox and submits the form, the database should update only the returned field to yes.
Any help would be appreciated.

Thanks.

<%@LANGUAGE=&quot;VBScript&quot;%>
<% Option Explicit

dim conn, rs,sCBTID, sName, sQuantaty,CBTID,var1, id,item, i, mysql


set conn = server.createobject(&quot;adodb.connection&quot;)
set rs = server.createobject(&quot;adodb.recordset&quot;)

conn.open &quot;cbtData&quot;

rs.open (&quot;SELECT * FROM cbt&quot;), conn,2,2
'rs.filter =&quot; CBTID = 16&quot;
%>

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Untitled</title>
</head>
<body>
<%
while not rs.eof%>
<form method=&quot;post&quot; name=&quot;test&quot; action=&quot;t2.asp&quot;>
<table border=&quot;1&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;33&quot; bordercolor=&quot;Yellow&quot;><input type=&quot;Checkbox&quot; name=&quot;chk_<%=rs(&quot;CBTID&quot;)%>&quot; value=&quot;<%=rs(&quot;CBTID&quot;)%>&quot;></td>
<td width=&quot;33%&quot; bordercolor=&quot;Yellow&quot; ><%=rs(&quot;Name&quot;)%></td>
<td width=&quot;33%&quot; bordercolor=&quot;Yellow&quot;><%=rs(&quot;Quantaty&quot;)%></td>
<td width=&quot;34%&quot; bgcolor=&quot;Purple&quot;> </td>
</tr>
</table>
<%rs.movenext
wend
%>
</table>

<br>
<input type=&quot;submit&quot; value=&quot;submit&quot; name&quot;b1&quot;>
</form>

<%
item = &quot;&quot;
for each item in request.form
'response.write(item)
if left(item,4) = &quot;chk_&quot; then
id = mid(item,5)
'build the sql line
mysql = &quot;update cbt select (cbt.return = yes) from CbtData where id = CBTID&quot;
conn.execute(mysql)
rs.requery
'response.write(&quot;the box checked&quot; )
'response.write(&quot;<p>&quot; &amp;&quot;the box u checked was &quot;&amp;&quot;</p>&quot; &amp;item)
'response.write(&quot;<p>&quot; &amp;id)
end if
next
%>
</body>
</html>

 
Try using set notation in your SQL statement:
Your SQL:
&quot;update cbt select (cbt.return = yes) from CbtData where id = CBTID&quot;

Try:
&quot;update cbt select (cbt.return = yes) from CbtData where id IN (&amp;&quot;CBTID&quot;&amp;)&quot;

I haven't tried this but in theory it should update all the items in the database that were selected on the previous page. Good luck, hope it helps.
sjf

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top