Click to See Complete Forum and Search --> : Close all recordsets with a loop
Dr_Michael
August 3rd, 1999, 03:56 AM
I have a lot of recordsets opened and I want to close all of them. Can I use a loop like this or not?
Dim rs as ADODB.Recordset
for Each rs In ??? 'here is my problem: which is the group?
rs.close
set rs = nothing
next
Thank you!
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Lothar Haensler
August 3rd, 1999, 04:49 AM
IMHO you can't because in ADO you can create standalone recordsets that do not have any connection to a database as in
dim rs as adodb.recordset
set rs = new adodb.recordset
rs.field.append
and so on.
There is no global collection of recordsets.
Dr_Michael
August 3rd, 1999, 04:51 AM
So sad :'-(
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Ravi Kiran
August 3rd, 1999, 04:59 AM
Hi,
I dont know about ADO. But with DAO i used to use some code like this: (a bit finer version, ofcource:-). Try it. Tell me if it works:
' This is kind of a background checker, that
' keeps dumping the no. of DBs open and No. of record sets open etc.
' It tries to access the global data that VB maintaines for you.
private Sub timerDbgDump_Timer()
Dim ii as Integer, jj as Integer, kk as Integer
Dim nc as Integer, nr as Integer
for ii = 0 to Workspaces.Count - 1
nc = nc + Workspaces(ii).Databases.Count
for jj = 0 to Workspaces(ii).Databases.Count - 1
nr = nr + Workspaces(ii).Databases(ii).Recordsets.Count
next jj
next ii
If (nc <> m_NC) Or (nr <> m_NR) then
If m_dbgdmpFptr = -1 then
Debug.print " Databases open = "; nc;
Debug.print " Recordsets open"; nr
else
print #m_dbgdmpFptr, " Databases open = "; nc;
print #m_dbgdmpFptr, " Recordsets open"; nr
End If
End If
m_NC = nc
m_NR = nr
End Sub
So you can use some loop like this and close all the record sets, (i think)
Ravi Kiran
Life is a comedy for those who think and a tragedy for those who feel
Dr_Michael
August 3rd, 1999, 05:16 AM
Nice coding friend, but I think it doesn't work and also I couldn't find a way of using a loop to close all of them. Your code does only counts the number of opened databases... Anyway, thank you!
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Ravi Kiran
August 3rd, 1999, 05:58 AM
That was not a code meant to be used as it is!!
It was only a base
You should try something like this
private Sub Command1_Click()
dim lprecset as RecordSet
...
for ii = 0 to Workspaces.Count - 1
nc = nc + Workspaces(ii).Databases.Count
for jj = 0 to Workspaces(ii).Databases.Count - 1
'nr = nr + Workspaces(ii).Databases(ii).Recordsets.Count
for kk = Workspaces(ii).Databases(ii).Recordsets.Count - 1 to 0 step -1
set lprecset = Workspaces(ii).Databases(ii).Recordsets(kk)
lprecset.Close
next kk
next jj
next ii
...
end sub
and here is a debug trace, on a sample with 3 data controls:
Databases open = 3 Recordsets open 9
Databases open = 3 Recordsets open 0
the second line is after closing all of them, which i do on the click of a btn (command1)
Ravi Kiran
Life is a comedy for those who think and a tragedy for those who feel
Lothar Haensler
August 3rd, 1999, 06:03 AM
the question referred to ADODB recordsets?
where do I find the Workspaces object in the ADO object model?
How do you close ADO recordsets with DAO methods?
Dr_Michael
August 3rd, 1999, 06:12 AM
I couldn't not to rate the previous answer :-D
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Dr_Michael
August 3rd, 1999, 06:14 AM
As Lothar said, it doesn't work. But I do really want to thank you for your try!
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.