View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Stevek Stevek is offline
external usenet poster
 
Posts: 8
Default Querytable Class Module

Hello All,

This is my first time trying create a Class Module with events. I cannot
seem to get the AfterRefresh Event to fire.
Any help would be appreciated. TIA

Steve

Here's what my Class Module (ClsModQt) looks like:
================================================== =============================
Public WithEvents qtQueryTable As QueryTable

Sub InitQueryEvent(qt As Object)
Set qtQueryTable = qt
End Sub

Private Sub qtQueryTable_AfterRefresh(ByVal Success As Boolean)
MsgBox ("Refreshed")
End Sub
================================================== =============================

Here what my Sub looks like:
================================================== =============================
Private Sub CreateQueryTable(ByVal SQLString, ByVal SheetName)

Dim Destination As Range
Dim qt As QueryTable
Dim MyQt As New ClsModQT

Set Destination = Worksheets(SheetName).Range("A5")
Worksheets(SheetName).Range("A5:Z400").ClearConten ts

' -- Delete the existing names on the sheet <--
For Each nm In Worksheets(SheetName).Names
nm.Delete
Next

' -- Delete the existing query tables on the sheet <--
For Each qt In Worksheets(SheetName).QueryTables
qt.Delete
Next

MyQt.InitQueryEvent _
qt:=Worksheets(SheetName).QueryTables(1)

ConnString = "ODBC;DSN=MyDSN;UID=MyID;PWD=MyPWD;Database=My Db;"

With Worksheets(SheetName).QueryTables.Add(Connection:= ConnString,
Destination:=Destination, Sql:=SQLString)
.Name = SheetName
.RefreshStyle = xlInsertDeleterows
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh
End With

End Sub

================================================== =============================