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!

Newbie question re Updates

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
I've never done this before, but Im trying to allow people to update their own records on an access database. I have a form that allows them to type in their first and last name. On submit, the asp code is supposed to find the record with their name and update the contents of a field called "alreadyformed" to "yes"

I keep getting an error message:Operation is not allowed when the object is closed.

I suppose they mean the recordset object, but I don't know what I'm doing wrong. Here's the code:

<%@ Language=VBScript %>
<html><body>
<%
dim objdc, cmdTmp, objrs
set objdc = Server.CreateObject(&quot;ADODB.Connection&quot;)
set cmdTmp = Server.CreateObject(&quot;ADODB.Command&quot;)
set objrs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objDC.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.Mappath(&quot;carpool.mdb&quot;) & &quot;;&quot;
dim strlastname
strlastname = Request.Form(&quot;lastname&quot;)
dim strfirstname
strfirstname = Request.Form(&quot;firstname&quot;)
cmdTmp.ActiveConnection = objdc

cmdtmp.CommandText = &quot;UPDATE table1 SET alreadyformed = yes WHERE lastname = '&quot; & strlastname &&quot;' and firstname = '&quot; & strfirstname &&quot;' ;&quot;
objrs.Open cmdTmp,,1,3
if objrs.EOF then
Response.Write&quot;<b>There are no records responding to your search</b><br><br><br>&quot;
End If
%>
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objdc.Close
Set objdc = Nothing
%>
 
Why do you have these lines?
objRS.MoveNext
Loop
because I don't see any While loop in your code.

Take them out to see if it solves your problem.
 
Thanks -- I tried that, but I still get the same error. Has anyone encountered this before? I'm really stuck on this...
 
Microsoft explains &quot;This error is returned to the browser when you try to run a SQL statement that does not return any records. For example, SQL clauses such as INSERT, UPDATE, DELETE, and/or stored procedures that do not return values may generate one of the above-mentioned error messages.&quot; See URL -
Or just try this:
<%@ Language=VBScript %>
<html><body>
<%
dim objdc
set objdc = Server.CreateObject(&quot;ADODB.Connection&quot;)
objDC.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.Mappath(&quot;carpool.mdb&quot;) & &quot;;&quot;
dim strlastname
strlastname = Request.Form(&quot;lastname&quot;)
dim strfirstname
strfirstname = Request.Form(&quot;firstname&quot;)

objdc.Execute(&quot;UPDATE table1 SET alreadyformed = 'no' WHERE lastname = '&quot; & strlastname & &quot;' and firstname = '&quot; & strfirstname & &quot;';&quot;)

objdc.Close
Set objdc = Nothing
%>
 
a few things
is this db in the root as you specify here
Server.Mappath(&quot;carpool.mdb&quot;) & &quot;;&quot;

have you checked for actual values in the form that were passed
'---> response.write Request.Form(&quot;lastname&quot;) etc...

you said you tried to get rid of the movenext but it didn't help. it does not belong there so don't put it back if you did.
You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
I think you should try pspringer's code. Usually, when you try to execute a sql statement that does not require to return a recordset (like Insert, Update, Delete, ...) then don't open a recordset. Use .Execute instead of .Open.
 
Thanks to everyone! -- pspringer, I used your code and everything works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top