Solved

Passing recordset back from function!

Posted on 2000-05-12
1
174 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
ID: 2806234
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 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

17 Experts available now in Live!

Get 1:1 Help Now