Solved

Declare Recordsets on the fly VB6?

Posted on 2009-05-15
5
590 Views
Last Modified: 2012-05-07
Hi, I'm trying to Declare and execute recordsets inside a loop.  I can't declare them all upfront because I don't know how many there might be.  Is it possible to pass a string as the name of a recordset?

I cleaned up the code to execute 10 times, but like I said, this isn't really the case.  The loop would execute a varying number of times.

Thanks
Dim intCounter As Integer
Dim strRS As String
Do Until intCounter = 10
 
    strRS = "rs" & intCounter
    
    Dim (strRS) As Recordset
    (strRS).Open strcon
   intcounter = intcounter + 1
Loop

Open in new window

0
Comment
Question by:zigmpls
[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
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 43 total points
ID: 24399996
If you have to keep all the recordsets open and hence cannot reuse the Recordset variable, you could declare an unsized array and ReDim it.

Dim intCounter As Integer
Dim RS () As Recordset

Do Until intCounter = 10
    redim preserve RS(intCounter)
   
    RS(intCounter).Open strcon
   intcounter = intcounter + 1
Loop
0
 
LVL 20

Assisted Solution

by:hes
hes earned 41 total points
ID: 24400224
Not to get into the why, that you need that open recordsets, I personally can't remember ever having to have open more than 2. But anyway, remember you are going to have to keep track of all of them no matter how you do open them, to close each one of them.
0
 

Author Comment

by:zigmpls
ID: 24400540
Thanks both for your feedback.  You're right; I was making this way too complicated.  I just declared one recordset before starting the loop, kept the information in an array and then closed the recordset at each iteration of the loop.


0
 
LVL 6

Assisted Solution

by:nirojexpert
nirojexpert earned 41 total points
ID: 24404785
also note that opening recordsets for each record (in a loop)  is not a good practise.
if possible, try to combine the sql so that you do not have to execute them in a loop. YOu should try to lessen the number of server requests.
maybe your first record set gets you a filtered list and inside the loop, you are getting additional value, setting value, etc.
you should attempt to combine the sql which gets you the list and what you want to do with time.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

738 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