[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Declare Recordsets on the fly VB6?

Posted on 2009-05-15
5
Medium Priority
?
598 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 172 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 164 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 164 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

649 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