Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Record set always available

Posted on 2000-03-08
3
Medium Priority
?
137 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:
Brendt Hess earned 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

609 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