+ Reply to Thread
Results 1 to 6 of 6

Return headers with results in 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

    Return headers with results in Recordset

    I'm pulling data from SQL databases using OLEDB.

    I can return the data (without headers) by using
    Please Login or Register  to view this content.
    or

    I can return the headers only by using
    Please Login or Register  to view this content.

    How can I return the data with its headers using the same recordset? (I'm joining the two arrays from above but it's inefficient. I want to do this in one operation.)
    *******************************************************

    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: Return headers with results in Recordset

    Unless I’ve missed something, Like this: https://stackoverflow.com/questions/...aders#24283834

  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: Return headers with results in Recordset

    Thanks for the suggestion Kyle. That looks like the code loops through the recordset fields and pastes them to a range (then pastes the rst contents to the range)

    I'm hoping that there is some advanced parameter which would allow me to set an array variable by
    Please Login or Register  to view this content.
    (or nearest equivalent) and have the field names in the first record of the array.

    Your suggestion is helpful in that I could bring 2 recordsets down to 1 however I would still need 2 array variables and then merge the 2 arrays together to get the desired output.
    Last edited by mc84excel; 10-24-2019 at 12:09 AM.

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

    Re: Return headers with results in Recordset

    There isn’t, you’ll need to loop through the headers, put them in an array and merge them with the data array.

  5. #5
    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: Return headers with results in Recordset

    That's what I was afraid of. Oh well, can't be helped. Will have to merge the two arrays then. Thanks Kyle.

    (In case anybody reading this wants to know what possible use for the header/field names included in the array = You can paste the array into an Excel workbook and it already has the field names, ready for inserting a table.)

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

    Re: Return headers with results in Recordset

    You can, but you wouldn’t use getrows for that. You’d use copyfromrecordset

+ 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. Userform Listbox Column headers from recordset or array?
    By puuts in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2016, 09:33 AM
  2. [SOLVED] Get recordset without the headers
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2016, 04:28 AM
  3. [SOLVED] Sort recordset results
    By dwbennett in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2015, 08:55 AM
  4. SQL Query to Count Results in Recordset
    By kortex in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-27-2012, 09:51 AM
  5. Replies: 2
    Last Post: 05-09-2012, 01:30 PM
  6. Querytable results into vba Recordset
    By Aaron in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2005, 06:18 AM
  7. [SOLVED] Web query results in a recordset?
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2005, 06: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