Solved

Record set always available

Posted on 2000-03-08
3
131 Views
Last Modified: 2010-05-02
I would like to create a record set and have it available throughout a module. I currently have the following lines:

  rs_VendorData.CursorLocation = adUseClient
  rs_VendorData.Open VendorDataSQLquery, ConnectionString, adOpenDynamic


My query and connectstring are defined at the top of my code on formload.

This code currently resides in the function I am calling so it is run every time (some 2000 times) when I place it in the calling procedure it is available the first time I call the function, once the function returns, the watchwindow will show all the elements in my recordset as out of context.

How does one set a recordset tyo be available for the "life" of a module.

Thanks.
0
Comment
Question by:scotts27
3 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 2597035
Assuming that the rs_VendorData object is global to the module (not local to the function), try something like this:

  If rs_VendorData.Status = adStateClosed Then

    rs_VendorData.CursorLocation = adUseClient
    rs_VendorData.Open VendorDataSQLquery, ConnectionString, adOpenDynamic
  End If

This will open the RS only if it is closed.  

Warning!  Be sure that your code doesn't make assumptions based on the fact that your recordset has just been opened!
0
 
LVL 1

Expert Comment

by:prozak
ID: 2597044
Try setting the value of Procedure to (All Procedures) in the Context frame on the Add Watch window. Additionally the recordset object should be declared at the top of the form with ConnectionString and query object.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2597487
Easiest way is to move it up to the module level. Declare a .BAS module and put the initialization and variable definitions there. Set the project properties to start in Sub Main() and open the recordset in that routine. Everyone, everywhere will have access to the data set.

Be sure to close the database connection down at exit time. You need a common exit handler so that the user clicking on [X] on any form will either be ignored or initiate an orderly shutdown.

Typically I have a Public Sub in the module called Die. It codes up as:

Public Sub Die()
'
Dim Frm as Form
'
On Error Resume Next
db.close
'
for each frm in forms
  unload frm
  set frm = nothing
next frm
'
end
'
end sub

M
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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