+ Reply to Thread
Results 1 to 5 of 5

use field names in ADODB query to an Excel workbook

  1. #1
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    use field names in ADODB query to an Excel workbook

    Hi,

    for a number of a circumstances I am trying to read from excel files as if they are databases to use the recordset in a VBA macro.
    it all goes nice and well, but I cannot use fieldnames on my query, I have to use SELECT * FROM ...
    and then use fieldIndex when extracting information with getRows(fields:=fA) where fA is a field index array

    I have tried puting names in brackets [], forward ticks, `` and nothing at all but nothing seems to work.


    Please Login or Register  to view this content.
    however, I do have managed to use field names in queries of querytables
    but have no idea how to achieve the same in code

    with the macro recorder I did get something as follows

    Please Login or Register  to view this content.
    Anyone can iluminate me?
    Thank you!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: use field names in ADODB query to an Excel workbook

    Why can't you use field names in the query?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    Re: use field names in ADODB query to an Excel workbook

    Because error occurs, failed to mention that.
    using * is the only way to get something

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: use field names in ADODB query to an Excel workbook

    What field(s) do you want to get from the recordset?

    By the way, what is COMMENTARIOc here?

    Is it a comma separated list of fields or something like that?

    PS What errors do you get when you specify the field names in the SQL statement?

  5. #5
    Forum Contributor
    Join Date
    09-30-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2010
    Posts
    274

    Re: use field names in ADODB query to an Excel workbook

    Nevermind, seems to be working now...
    but I have a feeling I'll be back soon.

    FWIW: if someone is here fighting with queries on excel files, you can concatenate fields putting like SELECT ([Field 1] & [Field 2]) as [Alias] FROM [Sheetname$]

+ 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. Excel ADODB Sql Query Execution taking hours when manipulate excel tables
    By brajesheee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2015, 01:41 AM
  2. Adodb Query with Offset?
    By nicholas.phillips in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-15-2014, 06:08 PM
  3. Show query column names behind pivot table field names
    By gbritton in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 11-18-2013, 03:17 PM
  4. Use Excel as Database by opening excel workbook as ADODB object
    By dragonvoice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2013, 04:13 AM
  5. Access Query via Excel (ADODB) - no error, but no output!
    By cml111 in forum Access Tables & Databases
    Replies: 3
    Last Post: 04-23-2013, 05:33 AM
  6. Complex ADODB-query
    By ino_mart in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2012, 05:41 PM
  7. MS Query Field Names
    By bowdent in forum Excel General
    Replies: 0
    Last Post: 05-22-2007, 09:50 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