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!

edit.asp - OPERATION=FIRSTIME, Editing an existing record in Access

Status
Not open for further replies.

techskool

Technical User
Jun 20, 2002
151
GB
Hi guys.

Ive got most of the asp pages for my site done now, Im just having trouble with when I try to edit an existing record.

Delete works fine (although of course it does its only RS.Delete!!)

The code below calls to iteslf, FIRSTIME allowing me to edit an existing record, and second time to actually recieve the posted data from the initial send and update the database, after droping past FIRSTIME on the second pass, going straight to EDIT and then RS.Update.

I recieve an IDref from the query string of the previous page, say the var = 44.

This is compared to a matching field in the database, in the SQL, (sql basically equates to pull a recordset out, when the value of the querystring IDref (44)matches the value 44 in the IDref field in the database.

The error I get is on FIRSTIME, where I try and display
the record contents in a form to give the user the oportunity to edit the fields.

i.e. &quot;<%=RS(&quot;Picture&quot;)%>&quot; as the value of Pisture, as the first line in the from throws out the error:

-----------
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/recordsnorthwest/edit.asp, line 51
-----------

There would appear to be a problem with the record I am trying to edit, but I am absolutely flummoxed if I can work this out.

PLEASE, PLEASE, PLEASE, someone help me

THE CODE:

<!--#include File=&quot;adovbs.inc&quot;-->
<%
dim conn
dim RS
dim strconn
dim sql
dim searchTerm

'set a local variable to my DSN-less connection String
strconn = &quot;DRIVER=Microsoft Access Driver (*.mdb);DBQ=&quot; & Server.MapPath(&quot;recordsnorthwest.mdb&quot;)

'Create the Connection object
set conn = server.createobject(&quot;adodb.connection&quot;)
conn.open strconn

'get the searchterm from check.asp
searchTerm=Request.QueryString(&quot;IDref&quot;)

'Create the recordset object
set rs = server.createobject(&quot;adodb.recordset&quot;)

sql=&quot;SELECT * FROM stock WHERE stock.IDref LIKE '%&quot;&searchTerm&&quot;%'&quot;

rs.open sql, conn, adOpenStatic, adLockOptimistic

%>
<html>
<head><title> edit.asp. Edit Contact Details </title>
<link href=&quot;css/main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head>
<body>
<!-- ************************* FIRSTIME *************************** -->

<%
'If this is the first time into this page, (operation=FIRSTIME) display
'the record contents in a form to give the user the oportunity to
'edit the fields

'If this is the second time into this page, (operation=EDIT) then display
'the record contents before writing the amended fields back to the RecordSet.

If Request.QueryString(&quot;operation&quot;)=&quot;FIRSTIME&quot; Then
%>
<div align=&quot;center&quot;><img src=&quot;images/recordsnorthwest_logo.jpg&quot; width=&quot;422&quot; height=&quot;34&quot;></div>
<h2> Edit Contact Details </h2>

<!-- Call same page but with the 'edit' operation -->
<form action=&quot;edit.asp?IDref=<%RS=(&quot;IDref&quot;)%>&operation=EDIT&quot; method=&quot;post&quot;></form>
<table width=&quot;650&quot;>
<tr><td></td><td></td><td><h4>Example</h4></td></tr>
<tr><td width=&quot;100&quot;>Picture</td><td> <input type=&quot;text&quot; name=&quot;Picture&quot; cols=40 value=&quot;<%=RS(&quot;Picture&quot;)%>&quot;> </td><td><tr><td width=&quot;100&quot;>Artist</td><td> <input type=&quot;text&quot; name=&quot;Artist&quot; cols=40 value=&quot;<%=RS(&quot;Artist&quot;)%>&quot;> </td><td>Asha</td></tr>
<tr><td width=&quot;100&quot;>Title</td><td> <input type=&quot;text&quot; name=&quot;Title&quot; cols=40 value=&quot;<%=RS(&quot;Title&quot;)%>&quot;> </td><td>JJ Tribute</td></tr>
<tr><td width=&quot;100&quot;>Label</td><td> <input type=&quot;text&quot; name=&quot;Label&quot; cols=40 value=&quot;<%=RS(&quot;Label&quot;)%>&quot;> </td><td>Beat Club</td></tr>
<tr><td width=&quot;100&quot;>Comment</td><td> <input type=&quot;text&quot; name=&quot;Comment&quot; cols=40 value=&quot;<%=RS(&quot;Comment&quot;)%>&quot;> </td><td>Italian Screamer</td></tr>
<tr><td width=&quot;100&quot;>Category</td><td> <input type=&quot;text&quot; name=&quot;Category&quot; cols=40 value=&quot;<%=RS(&quot;Category&quot;)%>&quot;> </td><td>Include any relevent categories; Italian Old Skool Piano House</td></tr>
<tr><td width=&quot;100&quot;>Year Made</td><td> <input type=&quot;text&quot; name=&quot;YearMade&quot; cols=40 value=&quot;<%=RS(&quot;YearMade&quot;)%>&quot;> </td><td>1991</td></tr>
<tr><td width=&quot;100&quot;>Price</td><td> <input type=&quot;text&quot; name=&quot;Price&quot; cols=40 value=&quot;<%=RS(&quot;Price&quot;)%>&quot;> </td><td>&pound;20.00</td></tr>
<tr><td width=&quot;100&quot;>Mp3</td><td> <input type=&quot;text&quot; name=&quot;Mp3&quot; cols=40 value=&quot;<%=RS(&quot;Mp3&quot;)%>&quot;> </td><td> </td></tr>
<tr><td width=&quot;100&quot;>Cost</td><td> <input type=&quot;text&quot; name=&quot;Cost&quot; cols=40 value=&quot;<%=RS(&quot;Cost&quot;)%>&quot;> </td><td>&pound;10.00</td></tr>
<tr><td width=&quot;100&quot;>Date Logged</td><td> <input type=&quot;text&quot; name=&quot;DateLogged&quot; cols=40 value=&quot;<%=RS(&quot;DateLogged&quot;)%>&quot;> </td><td>02/01/03 </td></tr>
<tr><td width=&quot;100&quot;>In Stock</td><td> <input type=&quot;text&quot; name=&quot;InStock&quot; cols=40 value=&quot;<%=RS(&quot;InStock&quot;)%>&quot;> </td><td>Yes</td></tr>
<tr><td width=&quot;100&quot;>Owner</td><td> <input type=&quot;text&quot; name=&quot;Owner&quot; cols=40 value=&quot;<%=RS(&quot;Owner&quot;)%>&quot;> </td><td>DT or GB</td></tr>
<tr><td><input type=&quot;submit&quot; value=&quot;Edit Contact&quot;></td><td>&nbsp;</td></tr>
</table>
</form>

<br><br>

<!-- ***************************** EDIT **************************** -->


<%
ElseIf Request.QueryString(&quot;operation&quot;)=&quot;EDIT&quot; Then

rs(&quot;Picture&quot;) = request.Form(&quot;Picture&quot;)
rs(&quot;Artist&quot;) = request.Form(&quot;Artist&quot;)
rs(&quot;Title&quot;) = request.Form(&quot;Title&quot;)
rs(&quot;Label&quot;) = request.Form(&quot;Label&quot;)
rs(&quot;Comment&quot;) = request.Form(&quot;Comment&quot;)
rs(&quot;Category&quot;) = request.Form(&quot;Category&quot;)
rs(&quot;YearMade&quot;) = request.Form(&quot;YearMade&quot;)
rs(&quot;Price&quot;) = request.Form(&quot;Price&quot;)
rs(&quot;Mp3&quot;) = request.Form(&quot;Mp3&quot;)
rs(&quot;Cost&quot;) = request.Form(&quot;Cost&quot;)
rs(&quot;DateLogged&quot;) = request.Form(&quot;DateLogged&quot;)
rs(&quot;InStock&quot;) = request.Form(&quot;InStock&quot;)
rs(&quot;Owner&quot;) = request.Form(&quot;Owner&quot;)

RS.Update
%>

<h2>Edit complete!</h2>
<br><br>
<table border=1 width=100%>
<tr>
<th>ID No.</th>
<th>Picture </th>
<th>Artist </th>
<th>Title </th>
<th>Label </th>
<th>Comment </th>
<th>Category </th>
<th>Year Made </th>
<th>Price </th>
<th>Mp3 </th>
<th>Cost </th>
<th>DateLogged </th>
<th>InStock </th>
</tr>
<tr align=&quot;center&quot;>
<td><%=RS(&quot;Owner&quot;)%><%=RS(&quot;IDref&quot;)%> </td>
<td><img src=<%=RS(&quot;Picture&quot;)%>></td>
<td> <%=RS(&quot;Artist&quot;)%> </td>
<td> <%=RS(&quot;Title&quot;)%> </td>
<td> <%=RS(&quot;Label&quot;)%> </td>
<td> <%=RS(&quot;Comment&quot;)%> </td>
<td> <%=RS(&quot;Category&quot;)%> </td>
<td> <%=RS(&quot;YearMade&quot;)%> </td>
<td> <%=RS(&quot;Price&quot;)%> </td>
<td><a href=<%=RS(&quot;Mp3&quot;)%>><img src=images/mp3_button.gif border=0></a></td>
<td> <%=RS(&quot;Cost&quot;)%> </td>
<td> <%=RS(&quot;DateLogged&quot;)%> </td>
<td> <%=RS(&quot;InStock&quot;)%> </td>
</tr>

</table>

<br><br>
Your amendment has been completed successfully.
<% End If %>

<!-- ***************************** FINISH *************************** -->
<!-- Link to go back to the start page. -->
<a href=&quot;default.asp&quot;>Return</a> back to menu
<br><br><br>
<a href=&quot;default.asp&quot;>Start page</a> <br>
<br><br>
</body>
</html>
 
Cheers for the advise but i sorted this a while back (forgotten I'd posted it here.)

It turned out to be a syntax error!doh!

Thanks for looking though browolf .

Regards

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top