I have the following code:
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=[dbname];", _
Destination:=Range("A1"))
.CommandText = Array( _
"SELECT field1, field2, field3, field4, field5, field6,
"FROM Table" _
, "99S" & Chr(13) & "" & Chr(10) & "WHERE (field1='something') AND (field2='123')" _
)
.Name = "Query from [dbname]"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
I would like to change the "AND (field2='123')" part to "AND (field2 in (123,321,456)) but i want to get this list from a cell with the exact text (i.e. (1,2,3)).
Please help!
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=[dbname];", _
Destination:=Range("A1"))
.CommandText = Array( _
"SELECT field1, field2, field3, field4, field5, field6,
"FROM Table" _
, "99S" & Chr(13) & "" & Chr(10) & "WHERE (field1='something') AND (field2='123')" _
)
.Name = "Query from [dbname]"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
I would like to change the "AND (field2='123')" part to "AND (field2 in (123,321,456)) but i want to get this list from a cell with the exact text (i.e. (1,2,3)).
Please help!