+ Reply to Thread
Results 1 to 10 of 10

OLE DB query and QueryTables object

  1. #1
    Registered User
    Join Date
    12-06-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    7

    OLE DB query and QueryTables object

    Hi,

    there is a sheet containing external data from an OLE DB query.
    I need to catch the „after refresh“ event and this works only for the QueryTables object, as far as I know.

    Unfortunately there is no QueryTable object on this sheet, a simple „MsgBox Sheets("MySheet").QueryTables.Count“ returns „0“.

    Root of my issue is the requirement to have a working Hyperlink()-formula inside the queryied data.
    The formula is created correctly by SQL Server, but will allways be displayed as text in the excel sheet.
    A small VBA routine is supposed to transform cell content from text to formula. This should happen after every refreshment.

    Thanks in advance for any help.

    Bests,
    Matze

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

    Re: OLE DB query and QueryTables object

    Just to check, what does:

    Please Login or Register  to view this content.
    return?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    12-06-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    7

    Re: OLE DB query and QueryTables object

    Thanks for reply,
    but it returns an error, number 1004

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

    Re: OLE DB query and QueryTables object

    Is the query actually refreshable in the UI? Is it returned as a Table in Excel?

  5. #5
    Registered User
    Join Date
    12-06-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    7

    Re: OLE DB query and QueryTables object

    Yes, the query delivers proper results.
    In online help I found something about an object OLEDBConnection.

    Funny to see there a two ribbons "Queries" and "Connections".
    The linked views are listed under Queries
    Attached Images Attached Images

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

    Re: OLE DB query and QueryTables object

    OK, then there is a querytable there, which you can refer to using Sheets("MySheet").Listobjects(1).QueryTable. So assuming you know how to hook into its events, you're good to go. If you don't, then you need a variable declared WithEvents in a class.

  7. #7
    Registered User
    Join Date
    12-06-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    7

    Re: OLE DB query and QueryTables object

    Yes, this is where I come from.

    Found a solution for that in stackoverflow, but it does not work
    beacause on Workbook_Open() no Querytable can be found:


    ______________________________________________________________________________________
    Class Modul

    Private WithEvents MyQueryTable As QueryTable

    Private Sub MyQueryTable_AfterRefresh(ByVal Success As Boolean)
    If Success Then
    MsgBox "done!"
    Else
    MsgBox "kaboom!"
    End If
    End Sub

    Friend Sub HookUpQueryTable(qt As QueryTable)
    Set MyQueryTable = qt
    End Sub

    ______________________________________________________________________________________
    Workbook

    Dim c As Class1

    Private Sub Workbook_Open()

    On Error Resume Next

    Set c = New Class1
    c.HookUpQueryTable Sheets("Verladungen").QueryTables(1)

    End Sub

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

    Re: OLE DB query and QueryTables object

    You need to use the syntax I just posted to get a reference to the querytable. It’s a property of the lost object, not the worksheet

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

    Re: OLE DB query and QueryTables object

    Listobject not lost object!

  10. #10
    Registered User
    Join Date
    12-06-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    7

    Re: OLE DB query and QueryTables object

    Thank you very much.

    It was a great help!

+ 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. [SOLVED] Microsoft Query - Set .Name Range with Scope = Workbook in the QueryTables.Add command
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2020, 11:36 AM
  2. How to replace items in CommandText for Database Query object?
    By slavrenz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2015, 01:04 AM
  3. Replies: 2
    Last Post: 04-10-2015, 04:35 AM
  4. Web query with QueryTables
    By fredoman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2009, 07:42 PM
  5. Web Query in Excel Worksheet Object
    By NewExcelUser in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-08-2006, 12:38 PM
  6. Replies: 2
    Last Post: 07-24-2006, 09:25 AM
  7. VBA Font Object Query
    By Robert Mulroney in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2005, 07:05 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