+ Reply to Thread
Results 1 to 4 of 4

mixing ADO and ODBC

  1. #1
    Forum Contributor
    Join Date
    08-09-2005
    MS-Off Ver
    2003 & 2007
    Posts
    111

    mixing ADO and ODBC

    I've got an Excel document I've built which uses multiple ODBC QueryTables

    Please Login or Register  to view this content.
    which were built using Excel's Connection Wizard. I periodically tweak the QueryTables by editing an SQL-string and then replacing the QueryTable's CommandText:

    Please Login or Register  to view this content.
    In the same Excel document I'm also using several ad hoc ADO queries against the same database, the results of which don't get embedded in a sheet but are used on-the-fly by my code.

    My problem is I'd really like the user to only have to log into the database *once* the first time the database is needed (when one of the QueryTables is refreshed or when one of the ad hoc queries is encountered). For single login access to all the ADO stuff I'm just storing the Connection object in a global variable, but I don't know how to integrate that with the QueryTables.

    I see that QueryTables can be created from ADO Recordsets, but then, from what I can tell, I won't be able to tweak the SQL and refresh.

    I'm going to try to learn about Windows Authentication, but I don't have control of the database permissions, so that may not work.

    I'd really appreciate any advice.
    Last edited by dlh; 01-05-2010 at 03:38 AM.

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

    Re: mixing ADO and ODBC

    You can overwrite the recordset used for a querytable, so you would need to change the SQL, retrieve a new recordset using your stored connection, then assign it to the querytable and refresh.
    If you need your users to be able to update the querytables manually too, then I think you will need to look at Integrated Security.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    08-09-2005
    MS-Off Ver
    2003 & 2007
    Posts
    111

    Re: mixing ADO and ODBC

    Thank you again, romperstomper. I hadn't realized I could assign a Recordset to an existing QueryTable. This seems promising, but can you please be more specific about the inability to update the table manually? Exactly what functionality goes away?

    If I use a dynamic cursor in the Recordset, will the Refresh method allow the QueryTable to respond to changes in the database? And does the CursorLocation matter?

    For tweaking the QueryTable's SQL (which won't happen very often), I think I can tell the user to update the SQL command and then have them run a special refresh macro (which would create a new Recordset, assign it to the QueryTable, and then refresh the QueryTable).

    (I'm going to test all of this as soon as I get access to the database again.)

  4. #4
    Forum Contributor
    Join Date
    08-09-2005
    MS-Off Ver
    2003 & 2007
    Posts
    111

    Re: mixing ADO and ODBC

    Marking the thread solved.

    If anyone else has a similar question, after you assign an existing Recordset to a QueryTable's Recordset property, the Excel UI's Refresh buttons (both right-click menu from within the QueryTable's range and the menu/ribbon item) become greyed out. This was an acceptable compromise for me.

    I don't know if subsequent calls to the VBA QueryTable.Refresh method will respond to updates in the underlying database, but I suspect it will not.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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