[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Programming Multiple Recordsets

Posted on 2002-07-25
4
Medium Priority
?
151 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 200 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
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…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

831 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