Solved

Programming Multiple Recordsets

Posted on 2002-07-25
4
146 Views
Last Modified: 2013-11-26
I'm using VB6 against an SQL Server database.
I have a form which has 6 combo boxes on a form, each loaded with ado recordsets.
To load each recordset, I have declared in the General Declarations section a recordset and an sql string for each one.
And, I use the same routine for each of the six comboboxes to load them:
Set RsSubCommCodes = New ADODB.Recordset
SqlObjects = "SELECT * FROM objects ORDER BY Description"
RsSubCommCodes.Open SqlObjects, Cn, adOpenStatic, adLockBatchOptimistic
    If Not (RsSubCommCodes.BOF And RsSubCommCodes.EOF) Then
        cboObjectDesc.AddItem Space
        RsSubCommCodes.MoveFirst
        While Not RsObjects.EOF
            cboObjectDesc.AddItem RsObjects!Description
            RsSubCommCodes.MoveNext
        Wend
    Else
        txtMessage = "You Are Not Assigned Any Agencies"
    End If
---------------------------------------------
My question is:
Is there an easier way to code for this?
I'm concerned because I think using too many recordsets is eating up all of the memory on the machine.
Can someone let me know if there is a better way?

Thanks in Advance
John

0
Comment
Question by:jtrapat1
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
aeklund earned 50 total points
ID: 7178207
You only have one recordset in your example.  But to make sure the recordset gets released along with the connection, add this to your code where <ConnectionObject> is your connection object:

Set RsSubCommCodes = New ADODB.Recordset
SqlObjects = "SELECT * FROM objects ORDER BY Description"
RsSubCommCodes.Open SqlObjects, Cn, adOpenStatic, adLockBatchOptimistic
Set <ConnectionObject>.ActiveConnection = Nothing
   If Not (RsSubCommCodes.BOF And RsSubCommCodes.EOF) Then
       cboObjectDesc.AddItem Space
       RsSubCommCodes.MoveFirst
       While Not RsObjects.EOF
           cboObjectDesc.AddItem RsObjects!Description
           RsSubCommCodes.MoveNext
       Wend
   Else
       txtMessage = "You Are Not Assigned Any Agencies"
   End If

RsSubCommCodes.Close
Set RsSubCommCodes = Nothing
<ConnectionObject>.Close
Set <ConnectionObject> = Nothing
0
 

Author Comment

by:jtrapat1
ID: 7178238
aeklund,

Thanks for the help.
Where should I put your code to close the recordsets and set the objects to Nothing?

Here's my situation:
The user clicks on a record in a datagrid and is brought to another form with that record in edit-mode.
Here is where I have the six comboboxes (all loaded with active recordsets).

Should I release the recordsets and connections when the user exits this form and returns to the datagrid?

Thanks

John
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 7181739
'''SELECT * FROM objects ORDER BY Description

if U just open recordset for Description

U should use

SELECT Description FROM objects ORDER BY Description

also

adOpenStatic, adLockBatchOptimistic
   is not needed to fill a combo

U can use read only , forward only
thus U can save Ur memory

0
 
LVL 10

Expert Comment

by:aeklund
ID: 7185332
As soon as the user is done editing the records, then I suggest release the resources.... so the queryunload event of the edit form would be a good place to do so.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
Copy a row 12 64
MS Date Picker 64 bit 32 bit issue 12 60
MS SQL Update query with connected table data 3 36
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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