Solved

Programming Multiple Recordsets

Posted on 2002-07-25
4
144 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

863 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

21 Experts available now in Live!

Get 1:1 Help Now