SkipVought
Programmer
First time in over 10 years of using QueryTables in Excel.
An application that I have been working on for several weeks as lost several QueryTables all at once, it seems.
As a matter of course, I code each QT, since I often substitute in my SQL and sometimes my Connection: one QT per sheet. Example...
Code:
Sub GetRespCodeUnion()
Dim sConn As String, sSQL As String, sPath As String, sDB As String
sPath = ActiveWorkbook.Path
sDB = Split(ActiveWorkbook.Name, ".")(0)
sConn = "ODBC;DSN=Excel Files;"
sConn = sConn & "DBQ=" & sPath & "\" & sDB & ".xls;"
sConn = sConn & "DefaultDir=" & sPath & ";"
sConn = sConn & "DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
sSQL = "SELECT DISTINCT Resp_CODE"
sSQL = sSQL & ", 'RqmtDate'"
sSQL = sSQL & ", 'RQQTY_275' "
sSQL = sSQL & "FROM `" & sPath & "\" & sDB & "`.`Data$` "
sSQL = sSQL & "UNION "
sSQL = sSQL & "SELECT DISTINCT Resp_CODE"
sSQL = sSQL & ", 'IssuDate'"
sSQL = sSQL & ", 'ISSUEQTY_275' "
sSQL = sSQL & "FROM `" & sPath & "\" & sDB & "`.`Data$` "
With wsRC_Week.QueryTables("qryRC_Week")
.Connection = sConn
.CommandText = sSQL
.Refresh BackgroundQuery:=False
Application.DisplayAlerts = False
.ResultRange.CurrentRegion.CreateNames True, False, False, False
Application.DisplayAlerts = True
End With
End Sub
Skip,
![[glasses] [glasses] [glasses]](/data/assets/smilies/glasses.gif)
POULTRY in motion to PULLET for a PALTRY amount!
![[tongue] [tongue] [tongue]](/data/assets/smilies/tongue.gif)