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!

If not in myRS response.redirect ... 3

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
US
This is being pulled from a previous page drop-down list
<%
reqid = request(&quot;vendorsdrop&quot;)
sql = &quot;Select * from vendors where id = &quot; & reqid '&quot;>&quot;
Dim myRS
set myRS=server.createobject(&quot;adodb.recordset&quot;)
myRS.open sql, &quot;dsn=db1&quot;
%>
My question is: How can I redirect or display an error message if the user forget to make a selection from the drop-down and simply submits the initial value of &quot;Select to Edit&quot;

Only if I really helped you
|
|
|
|
V (-:
 
if request(&quot;vendorsdrop&quot;) = &quot;Select to Edit&quot; then
response.redirect(&quot;wherever.asp&quot;)
end if

and you should specify whether you are asking for request.querystring or request.form --

It will improve performance.

:)
 
thanks LINK9.
Now, I'm getting this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error. in query expression 'id = Select Vendor'.

/mysite/mypage.asp, line 6

****************************
I changed it abit, tell me if I did wrong.
if reqid = &quot;Select Vendor&quot; then
response.redirect(&quot;error.asp&quot;)
end if

Tony
(-:
 
Instead of Validating server-side, do it on client BEFORE Submit:
<Input Type=Button Value=Submit OnClick=Validate()>

<Script Language=VBScript>
Private Sub Validate()
If MyForm.vendorsdrop.Value = &quot;Select to Edit&quot; then
MsgBox &quot;You MUST select a vendor&quot;
Exit Sub
End if
(other validations)
MyForm.Submit
end if

End Sub
</Script>

This not only saves round trips to the server, but if the user has filled out other info, they won't have to re-enter it!
 
Yes, that's fine, but your error is where you are creating your SQL Statement

&quot;Select * from vendors where id = &quot; & reqid '&quot;>&quot;

should be

&quot;Select * from vendors where id = '&quot; & reqid & &quot;'
 
Thanks Link9.
TimLarkin, thanks for your suggestion bud, makes lot of sense, and trying it now. thaks both. Tony
(-:
 
Now I'm having a differnt problem, I apologize for the long code, but it's not working and I don't know where the problem is
Here's the error I'm getting
Microsoft VBScript runtime error '800a000d'

Type mismatch

/mysite/Vendorsfinal.asp, line 3
***************************************************

<%
sql = &quot;UPDATE mytable SET &quot;
sql = sql & &quot;accnumber = '&quot; & RSvfinal(&quot;accnumber&quot;) & &quot;'&quot;
sql = sql & &quot;company = '&quot; & RSvfinal(&quot;company&quot;) & &quot;',&quot;
sql = sql & &quot;address1 = '&quot; & RSvfinal(&quot;address1&quot;) & &quot;',&quot;
sql = sql & &quot;address2 = '&quot; & RSvfinal(&quot;address2&quot;) & &quot;',&quot;
sql = sql & &quot;city = '&quot; & RSvfinal(&quot;city&quot;) & &quot;',&quot;
sql = sql & &quot;state = '&quot; & RSvfinal(&quot;state&quot;) & &quot;',&quot;
sql = sql & &quot;zip = '&quot; & RSvfinal(&quot;zip&quot;) & &quot;',&quot;
sql = sql & &quot;country = '&quot; & RSvfinal(&quot;country&quot;) & &quot;',&quot;
sql = sql & &quot;phone = '&quot; & RSvfinal(&quot;phone&quot;) & &quot;',&quot;
sql = sql & &quot;fax = '&quot; & RSvfinal(&quot;fax&quot;) & &quot;',&quot;
sql = sql & &quot;email = '&quot; & RSvfinal(&quot;email&quot;) & &quot;',&quot;
sql = sql & &quot;website = '&quot; & RSvfinal(&quot;website&quot;) & &quot;',&quot;
sql = sql & &quot;contact = '&quot; & RSvfinal(&quot;contact&quot;) & &quot;',&quot;
sql = sql & &quot;status = '&quot; & RSvfinal(&quot;status&quot;) & &quot;',&quot;
sql = sql & &quot;paymentdays = '&quot; & RSvfinal(&quot;paymentdays&quot;) & &quot;',&quot;
sql = sql & &quot;paymentdate = '&quot; & RSvfinal(&quot;paymentdate&quot;) & &quot;',&quot;
sql = sql & &quot;settlediscount = '&quot; & RSvfinal(&quot;settlediscount&quot;) & &quot;',&quot;
sql = sql & &quot;settledays = '&quot; & RSvfinal(&quot;settledays&quot;) & &quot;',&quot;
sql = sql & &quot;settledate = '&quot; & RSvfinal(&quot;settledate&quot;) & &quot;',&quot;
sql = sql & &quot;terms = '&quot; & RSvfinal(&quot;terms&quot;) & &quot;',&quot;
sql = sql & &quot;vendor1099 = '&quot; & RSvfinal(&quot;vendor1099&quot;) & &quot;',&quot;
sql = sql & &quot;taxid = '&quot; & RSvfinal(&quot;taxid&quot;) & &quot;',&quot;
sql = sql & &quot;postmaster = '&quot; & RSvfinal(&quot;postmaster&quot;) & &quot;',&quot;
sql = sql & &quot;entryoffice = '&quot; & RSvfinal(&quot;entryoffice&quot;) & &quot;'&quot;

Dim RSvfinal
set RSvfinal=server.createobject(&quot;adodb.recordset&quot;)
RSvfinal.open sql, &quot;dsn=db1&quot;

%>
Tony
(-:
 
You are trying to assign values to the sql statement from a variable that hasn't been created yet --

You are trying to open it after all that???

I don't think I get it...

 
So, the THIS should go first before my sql update statement??

Dim RSvfinal
set RSvfinal=server.createobject(&quot;adodb.recordset&quot;)
RSvfinal.open sql, &quot;dsn=db1&quot;


Here's what I have in a nutshell:
1.My default page display a drop-down box displaying account numbers from the Database
2. User select any account number to edit and submits
3. After submitting, the next page displays every field in database to edit because I don't know what fields need updating.

What I intended to do with my loooong sql &quot;UPDATE&quot; statement was to update all fields after user makes change and submits.



Tony
(-:
 
Ok, I think you've got the right idea, but you're a bit off in the concept...

First, you shouldn't use an UPDATE statement to &quot;open&quot; a recordset. See how the two ideas conflict? A recordset is used to hold data, and therefore, you should use a SELECT statement to open it... i.e. a statement that returns some data...

The UPDATE is just going to do its thing and that's it, returning nothing...

If you want to use an UPDATE statement, then by all means, use one... it's much more efficient than updating a recordset record by record, and then updating it back to the database, but you should use the .execute method of your connection object to do so...

conn.execute(&quot;UPDATE empID SET empID = 2587 WHERE empID=2589&quot;)

or build your string, and pass it in --

but instead of trying to build it up from a recordset that hasn't been created, build it from your request.form values...

sql = &quot;UPDATE mytable SET &quot;
sql = &quot;empID='&quot; & request.form(&quot;empID&quot;) & &quot;'&quot;

and so on...

hope this clears something up for ya

:)
Paul Prewett
 
I finally got it to work bro.
1. The original Page, allows users to selet a record by Account Number
2. They make necessary changes - submit
3. Changes are made

Thanks for all you help. I beginning to understand this ASP thing a lot better. Tony
(-:
 
Hey, if I might make a suggestion, there's a book out there called &quot;Professional ADO & RDS Programming with ASP&quot; published by WROX Press and written by John Papa and four other guys.

I wouldn't call it good, because if I did, I'd be shortchanging it.

I have the 2.0 version (ADO), and so they probably have an updated version of it now, but anyone programming with ASP and ADO should have this book on their desk and have read it cover to cover at least once.

For that matter, if you ever want to buy a book on any aspect of programming, WROX is all you should buy. They're the easiest reading and best written books out there IMHO.

:)
Paul Prewett
 
I will follow your advice link9, and I appreciate experts like you that are always willing to help. Tony
(-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top