LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Class Module Bill Martin[_2_] Excel Programming 6 January 25th 06 08:56 PM
Class Module Todd Huttenstine Excel Programming 2 May 21st 04 11:17 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"