Solved

Record set always available

Posted on 2000-03-08
3
132 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

749 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