Solved

Passing recordset back from function!

Posted on 2000-05-12
1
172 Views
Last Modified: 2011-09-20
I have a web page which has a function. The function queries a database and returns back a recordset.

The problem is I can't do the usual things that I can do with a regular recordset (like, MoveNext). Below's the code.


Dim objResource
Dim rsResources

rsResources = ShowResource()

Do While Not rsResouces.EOF

      Response.Write rsResources("resource_id") & ": " & rsResources("resource_name") & "<BR>"

      rsResources.MoveNext

      Response.Write rsResources("resource_name") & "<BR>"

Loop

Function ShowResource()

      Dim rsResource
      Dim conResource
      Dim strSQL
      Dim objCalendar
      Dim strDSN

      Set conResource = Server.CreateObject("ADODB.Connection")

      strDSN = "driver=sql server;database=db1;server=server1;uid=sa;pwd=password"

      conResource.Open strDSN
      
      strSQL = "sp_ShowRecords"

      Set rsResource = conResource.Execute(strSQL)

      Set ShowResource = rsResource
      
End Function
0
Comment
Question by:hobster
1 Comment
 
LVL 3

Accepted Solution

by:
MikeRenz earned 50 total points
Comment Utility
change your
  Function ShowResource()
to
  Function ShowResource() as Recordset


if that doesn't do it for you, then you must use this:
 
  Function ShowResource(ByRef myRS)
    ...
    Set myRS = conResource.Execute(strSQL)
  End Function

and then call the function like this:

  ShowResource rsResource



btw...this question should be asked in the ASP section, not the VB section of EE
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now