Solved

Declare Recordsets on the fly VB6?

Posted on 2009-05-15
5
586 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
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

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…

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

26 Experts available now in Live!

Get 1:1 Help Now