+ Reply to Thread
Results 1 to 3 of 3

Comparing Variant Array to ADODB.Recordset?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Comparing Variant Array to ADODB.Recordset?

    I'm hoping someone can help out a SQL rookie here.

    I frequently have the following scenario: I have a variant array of values that I need to compare to a database. Currently I am passing the array to a VBA function, the function sets the ADODB connection and then loops through the array. On each loop, it alters the SQL query to the current value from the array and then retrieves a recordset. (If it helps visualise what I am doing, I have posted the code at the bottom of this post)

    I feel that this is inefficient and it would be much quicker to match the arrays values in SQL instead.

    Is it possible to somehow 'join' the array with the SQL query before retrieving the recordset?
    Could the array be converted to a recordset and then somehow 'join' the recordset??
    Any other method I am not aware of?


    UPDATE: Joining the database to the arrays source is not an option.


    APPENDIX:
    Please Login or Register  to view this content.
    Last edited by mc84excel; 09-10-2015 at 08:04 PM.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing Variant Array to ADODB.Recordset?

    Without seeing the SQL it's impossible to say, but can't you just use an in clause with all your criteria?

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Comparing Variant Array to ADODB.Recordset?

    Quote Originally Posted by Kyle123 View Post
    Without seeing the SQL it's impossible to say,
    Well I have a number of different projects that make use of the function I am using for now and all of their SQL queries are different. The one thing in common is that they are all SELECT queries and they end with the WHERE criteria = ' (The VBA function repeatedly calls this query with each value in the array)

    Quote Originally Posted by Kyle123 View Post
    but can't you just use an in clause with all your criteria?
    You mean write the SQL so it's like '...WHERE field IN ( 1d array )' ? I hadn't thought of that! Hmmm I would need to convert the array to a string first I guess... I'll play around with this idea and see what happens.

    UPDATE: Perfect. Thank you very much Kyle. The speed increase turned out a lot better than I hoped for. The macros using the new function are now up to 15x faster! If anyone needs this, see my current WIP below. If you found this useful, please rep Kyle in the previous post!

    Please Login or Register  to view this content.
    Last edited by mc84excel; 09-16-2015 at 10:37 PM.

+ 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. Help with comparing Variant Array with itself
    By mtpyankee in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-18-2014, 03:33 PM
  2. Refresh ADODB Recordset
    By oteixeira in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-01-2011, 04:12 AM
  3. Check if equal: Cells with adodb recordset
    By Huija in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2008, 01:25 AM
  4. [SOLVED] ADODB.Recordset from workbooks : numbers only?
    By JVLin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2006, 12:00 AM
  5. How do I retrieve the column names in a ADODB recordset from MS SQ
    By MChrist in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2005, 09:05 AM
  6. problem using isnull() to check a value in ADODB.Recordset
    By tilmP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-18-2005, 04:06 AM
  7. [SOLVED] Delete ADODB Recordset
    By Jim Thomlinson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2005, 01:06 AM

Tags for this Thread

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