Solved

Record set always available

Posted on 2000-03-08
3
133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

724 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