+ Reply to Thread
Results 1 to 4 of 4

Set Command String for Query - Excel 2013

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Set Command String for Query - Excel 2013

    I have a query that connects to another Excel spreadsheet. According to everything I've been able to find, the following should reset the connection:

    ActiveSheet.QueryTables(1).Connection = Range("Conn_string")

    There is data on the sheet, and it does refresh.

    Yet: activesheet.querytables.count is ZERO! I cannot set the querytable, because there isn't a query table on the sheet.

    MsgBox ActiveWorkbook.Connections("qry_data").ODBCConnection.Connection shows me the current connection string.

    ActiveWorkbook.Connections("qry_data").ODBCConnection.Connection = Range("Conn_String") Gives me Run-time error 5: Invalid call or argument.

    Any ideas? Should I be pursuing the non-existent Query Table or is there some incantation to set ActiveWorkbook.Connections("qry_data").ODBCConnection.Connection to the desired string.

    And yes: Set ActiveWorkbook.Connections("qry_data").ODBCConnection.Connection doesn't work either. It says object required.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Set Command String for Query - Excel 2013

    Things that don't work:

    ActiveWorkbook.Connections("qry_data").ODBCConnection.Connection = Range("Conn_String")
    ActiveSheet.ListObjects(1).Item.QueryTable = Range("Conn_String")
    ActiveSheet.ListObjects(1).Item.QueryTable.WorkbookConnection = Range("Conn_String")
    MsgBox ActiveSheet.QueryTables.Count = 0
    MsgBox ActiveSheet.ListObjects(1).QueryTables.Count (fail)
    MsgBox ActiveSheet.ListObjects(1).Item.QueryTables.Count (fail)


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Set Command String for Query - Excel 2013

    I'll post the solution when the site allows me.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Set Command String for Query - Excel 2013

    It was the ODBC Connection after all.
    Please Login or Register  to view this content.

+ 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 2013 - complicated search function query
    By jonbar123 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-28-2015, 01:06 PM
  2. [SOLVED] Using ADO/DAO in Excel 2013 to query an .accdb database hard crashes Excel
    By 1aaaaaaaaaaaaaaa in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-25-2015, 07:15 PM
  3. Need help converting Excel 2013 command into Excel 2010
    By xMaximus in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-03-2015, 06:24 PM
  4. Running Excel 2013 VBA/web query when screen is locked....
    By AndyDD_UK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2015, 11:45 AM
  5. Replies: 1
    Last Post: 07-07-2014, 04:42 PM
  6. [SOLVED] Excel sql query / WHERE command referring to a specific cell value
    By mlcfexcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2014, 10:43 AM
  7. Excel 2007 : Excel 2007 VBA command button query
    By Airwilf in forum Excel General
    Replies: 0
    Last Post: 11-18-2010, 06:11 AM

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