By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Problems Using UPDATE to modify multiple and non sequential records - a giant conundrum from a total novice....

P: n/a
The records in my database are displayed in a form as follows:
<form action="report-ammend1.42.asp" method="post"name="form">
<table border=1>


x = 1
while RS.EOF=false
<tr><td><input type="hidden" name="SprogNo<%= x %>"
value="<%Response.Write RS.Fields("SprogNo")%>"><% response.write
<td><input type="text" name="Report<%= x %>" value="<%Response.Write
<td><input type="text" name="rep2<%= x %>" value="<%Response.Write

x = x + 1
By specifying integer values for x in the form action file, the
correct data is always udated to the correct record:

Dim DB

Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
'Dim rs
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM SprogTbl", DB, 2, 2
for x = 1 to 3
rs.Fields("SprogNo") = Request.Form("SprogNo" & x)
rs.Fields("Report") = Request.Form("Report" & x)
rs.Fields("rep2") = Request.Form("rep2" & x)
However, I need this to work for any (undefined) no. of records and
the records may have been queried to display non-sequential records
for the database.
I can't make any of the three solutions I can think of work:
1. If I could make the field SprogNo (which contains the unique ID
no.) rs.response write into x as an integer, then each record would be
automatically numbered. I would then need some kind of "for each x"
loop before the rs.update statements. Just putting:

Response.Write RS.Fields("SprogNo")=x

in place of x = x+1 doesn't do it........

2. I've also tried tying the update to a WHERE statement. But, the
following will work for a databse of one record only:

Dim strSQL
strSQL = "UPDATE SprogTbl SET Report = '" & Report & _
"', rep2 = '" & rep2 & _
"' WHERE ((SprogTbl.SprogNo)='" & SprogNo & "');"

..... however, I've had no success trying to iterate it's functions
starting with rs.movefirst and then a while rs.EOF=false 'rs.movenext

3. Finally, I thought it might be worth trying to get the WHERE
statement (above) into the rs.Fields("SprogNo") =
Request.Form("SprogNo" & x) statement. So far all attempts have fallen
foul of syntax errors. e.g. rs.update WHERE ((SprogTbl.SprogNo)='" &
SprogNo & "');
The last two solutions would still require making the update repeat
for each of the fields in some kind of a loop.

Any help gratefully recieved......
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.