473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Returning a recordset from a function

I have a function "ReturnDocumentRules" that returns a recordset. Everything works if I do not close the recordset and set it to nothing, but I know this is bad programming practice. If I do close the recordset and set it to nothing, obviously after I have set the function to the recordset, return value is still set to nothing.

My code:

Expand|Select|Wrap|Line Numbers
  1. Public Function ReturnDocumentRules() As Recordset
  2.     'Open DB and retrieve rules from Rules table that apply to selected document
  3.     Dim db As Database, rs As Recordset
  4.     Set db = OpenDatabase("H:\9000\9000.mdb")
  5.     Set rs = db.OpenRecordset("SELECT rule FROM Rules WHERE docID=" & frm_mainMenu.cb_DocType.Value _
  6.         & " ORDER BY docID", dbOpenSnapshot)
  7.  
  8.     Set ReturnDocumentRules = rs
  9.  
  10.     rs.Close
  11.     db.Close
  12.     Set rs = Nothing
  13.     Set db = Nothing
  14.  
  15. End Function
  16.  
How can I return this recordset and still properly close it in the function?
Jan 9 '09 #1
4 7009
danp129
323 Expert 256MB
You should be able to return a disconnected recordset:
4GuysFromRolla.com - Using Disconnected Recordsets
Jan 9 '09 #2
An additional option would be to declare class level variables in the general declaration of the class. Then use the those varables in your returndocumentrules function. Then close the db and recordset after your done calling the function in you main calling code. For example:
public class abc()
Dim db As Database, rs As Recordset
function ReturnDocumentRules()
db = x
rs = y
end function
private sub button_click()
returndocumentrules()
rs.close
db.close
end sub
end class
Jan 12 '09 #3
Thanks Dan,

The disconnected recordsets worked perfectly. In addition to that link, I read this and this to get it implemented.
Jan 12 '09 #4
i m also stuck in this problem

i cant close the record set
thanks
Jan 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sean | last post by:
HI, I would like to know if I can some set a variable to return a single value from a function using the set command. Is this possible? Thanks in advance for your answer Sean
1
by: Robin Hammond | last post by:
Can anybody tell me why a) when running a stored proc from an asp page to return a recordset the command succeeds if the sp queries an existing table directly, but b) if the stored proc populates...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
5
by: Robert Fitzpatrick | last post by:
Can someone point me to some more information or perhaps show an example of returning a recordset from a plpgsql function. I'd like to send an argument or arguments to the function, do some queries...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
1
by: vinodkus | last post by:
I M BEGINNER IN ASP I WANT TO RETURN TOTAL RECORDS FROM A TABLE. THERE ARE TWO FORMS CLASS1.ASP AND CLASS2.ASP THROUGH FIRST FORM I JUST POST THE NAME OF TABLE SO I M WRITING THE CODE OF...
1
by: zeeshan12 | last post by:
Hi, I am running a simple select query on a connection with mysql database. On returning recordset froma function object I get an "Invalid use of property" error. I have no idea why its doing...
7
by: ChrisHardie | last post by:
I am somewhat new to Access and I am trying to create a recordset to get data from the local access db. I get an error stating "Either BOF or EOF is True, or the current record has benn deleted..." ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.