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

record sets and functions...strange

Status
Not open for further replies.

skotman

ISP
Sep 11, 2003
328
US
I've got a strange problem. When I run the clode below as is, it looks as though it's not creating the RS object.

Code:
<!--#include virtual="\adovbs.inc"-->
<%
url = Request.ServerVariables("url") & "?"

Function displayReport(machine)
'response.Write("machine:" & machine)

SQL = "Select * From machineReports order by ID Asc"
If machine <> "" Then SQL = "Select * from machineReports where machine = '" & machine & "'"

RSconnect(SQL)

If RS.EOF Then
Response.Write("No comments found")
Else
%>
<table width="100%" border="0">
  <tr>
    <th>Machine</th>
    <th>Date</th>
    <th>Comment</th>
  </tr>
<%
Do while NOT RS.EOF
%>
  <tr>
    <td><%=RS("machine")%></td>
    <td><%=RS("commentDate")%></td>
    <td><%=RS("comment")%></td>
  </tr>
<%
RS.MoveNext()
Loop
End If
End Function

Function RSconnect(SQL)
Response.Write(SQL & "<BR>")
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = "dsn=testMachine;"
RS.Source = SQL
RS.CursorType = 0
RS.CursorLocation = 2
RS.LockType = 3
RS.Open


End Function


'============================================================
Select Case Request.QueryString("act")

Case "showReport"
machine = request.QueryString("machine")
displayReport(machine)

End Select
%>

But when it works when I take everything in the function RSconnect(SQL) and replace the function call with the code thats in the function... so it looks like:

Code:
<!--#include virtual="\adovbs.inc"-->
<%
url = Request.ServerVariables("url") & "?"

Function displayReport(machine)
'response.Write("machine:" & machine)

SQL = "Select * From machineReports order by ID Asc"
If machine <> "" Then SQL = "Select * from machineReports where machine = '" & machine & "'"

Response.Write(SQL & "<BR>")
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = "dsn=testMachine;"
RS.Source = SQL
RS.CursorType = 0
RS.CursorLocation = 2
RS.LockType = 3
RS.Open

If RS.EOF Then
Response.Write("No comments found")
Else
%>
<table width="100%" border="0">
  <tr>
    <th>Machine</th>
    <th>Date</th>
    <th>Comment</th>
  </tr>
<%
Do while NOT RS.EOF
%>
  <tr>
    <td><%=RS("machine")%></td>
    <td><%=RS("commentDate")%></td>
    <td><%=RS("comment")%></td>
  </tr>
<%
RS.MoveNext()
Loop
End If
End Function

Function RSconnect(SQL)
Response.Write(SQL & "<BR>")
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = "dsn=testMachine;"
RS.Source = SQL
RS.CursorType = 0
RS.CursorLocation = 2
RS.LockType = 3
RS.Open


End Function


'============================================================
Select Case Request.QueryString("act")

Case "showReport"
machine = request.QueryString("machine")
displayReport(machine)

End Select
%>


any ideas? I'm at a loss here. The error I'm getting is:
Code:
Microsoft VBScript runtime error '800a01a8' 

Object required: 'RS' 

/testreport/default.asp, line 60

Scott Heath
AIM: orange7288
 
It may be a variable scope issue. Right now the code is dynamically allocating space fgor your variables and trying to guess at what scope they exist in. Try Dim'ing your RS variable near the top before the function declarations to force it to be a global variable.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top