Solved

Record set always available

Posted on 2000-03-08
3
127 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
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…
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…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now