[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Declare Recordsets on the fly VB6?

Posted on 2009-05-15
5
Medium Priority
?
600 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
4 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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 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