CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Close all recordsets with a loop

    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

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Close all recordsets with a loop

    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.


  3. #3
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    OK thanx.

    So sad :'-(

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Close all recordsets with a loop

    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

  5. #5
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Close all recordsets with a loop

    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

  6. #6
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Close all recordsets with a loop

    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

  7. #7
    Join Date
    May 1999
    Posts
    3,332

    Re: Close all recordsets with a loop

    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?


  8. #8
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    There were a little bit confusion round there!

    I couldn't not to rate the previous answer :-D

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  9. #9
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Not working but thanx for the try!

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured