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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Help for VBScript

Status
Not open for further replies.

hdog

Technical User
Mar 24, 2002
26
US
I am new to VBscript and am trying to pull a record using a variable (numeric) from another record. I keep getting an error and don't know enough to know how to fix it. I am using dreamweaver to build the script. Can someone please help?

Here is may code:
<%
Dim rate_type__mm_var
rate_type__mm_var = "0"
If (Request.Form("custom") <> "") Then
rate_type__mm_var = Request.Form("custom")
End If

Dim rate_type
Dim rate_type_numRows

Set rate_type = Server.CreateObject("ADODB.Recordset")
rate_type.ActiveConnection = MM_kradb_STRING
rate_type.Source = "SELECT * FROM Rate_Information WHERE rate_type_id=" + Replace(rate_type__mm_var, "'", "''") + ""
rate_type.CursorType = 0
rate_type.CursorLocation = 2
rate_type.LockType = 1
rate_type.Open()

rate_type_numRows = 0

rate_type.Close()
Set rate_type = Nothing
%>
 
What is the error message?

You assign this variable to another variable, but I don't see where you've assigned any value to it or declared it:

MM_kradb_STRING

You also assign a value of zero

rate_type_numRows = 0

but never use the variable.

Lee
 
The variable MM_kradb_STRING is assigned in another asp include file referenced prior in the code. The rate_type_numRows=0 is generated by Dreamweaver and is always in the code. The problem seems to be in the variable:

Replace(rate_type__mm_var, "'", "''") + ""

The server logs show nothing other than the post and this is a page posting back an IPN response to paypal so I see nothing on the page. I do have an error trap showing:

"The connection cannot be used to perform this operation. It is either closed or invalid in this context.
 
as a start..
replace this line:

rate_type.Source = "SELECT * FROM Rate_Information WHERE rate_type_id=" + Replace(rate_type__mm_var, "'", "''") + ""

with this:

rate_type.Source = "SELECT * FROM Rate_Information WHERE rate_type_id=" & Replace(rate_type__mm_var, "'", "''") & ""

May be the cause of your error, and should be fixed anyway - but it may also be your connection string, you will need to test that this is what you believe it to be:

response.write(MM_kradb_STRING)

If the first point doesn't resolve please post the result of the above.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Found the problem! My connection string was pointing to the wrong place!! It's always the simplest things that trip me up. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top