+ Reply to Thread
Results 1 to 7 of 7

Looping through tables and using recordset objects

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Looping through tables and using recordset objects

    Hi Guys,

    i have code like here:

    Please Login or Register  to view this content.
    and have easy question: if i want to do a loop through all the tables (like i have the 5 tables where i would use the similar sql) should i break every time adodb connection and recreate or just use one connection?
    If yes how can i do this? Or better practice is to clean connection and recordset ?

    Or maybe it is possible to create connection to workbook once but change onlt table name within it?

    Please help,
    Jacek

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Looping through tables and using recordset objects

    The connection is to the workbook, not to a specific table. The SQL query is what determines which table you are looking at.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Looping through tables and using recordset objects

    thank you Rory,

    so i should open conection once and only reset recodsets?

    Best,
    Jacek

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Looping through tables and using recordset objects

    It depends on what you are doing. You should ideally not keep a connection open any longer than necessary. If you are opening a connection and running 5 queries one after the other, it doesn't make sense to keep opening and closing the connection.

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Looping through tables and using recordset objects

    thank you Rory!

    Why not to keep it open too long ?

    Best,
    Jacek

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Looping through tables and using recordset objects

    Because of file/record locking. If nobody else could be using the file it's probably not an issue but it's a bad habit to get into.

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Looping through tables and using recordset objects

    thank you !

    Best wishes for you,
    Jacek

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Recordset Looping
    By Cobra17 in forum Access Programming / VBA / Macros
    Replies: 5
    Last Post: 10-06-2021, 05:40 PM
  2. [SOLVED] Help with looping over pre-defined list of objects
    By ironfelix717 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2018, 04:01 PM
  3. [SOLVED] Help with looping/dumping recordset
    By jsabo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2015, 05:29 PM
  4. Looping through Objects and giving them appropriate hyperlinks
    By JoeSkittles in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2013, 08:30 AM
  5. Creating, Opening and Closing Connection and Recordset Objects
    By DGB48 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2013, 04:36 PM
  6. ADO Connection vs Recordset objects.
    By DaveO in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2006, 09:45 AM
  7. [SOLVED] Looping Thru Objects in UserForms
    By RobC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2005, 07:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1