SQL query in VBA with QueryTable Object
Hello
I am trying to import selected data from a comma separated text file using the following method.
Sub PerformQuery()
Dim thisSheet As Worksheet
Set thisSheet = ThisWorkbook.Worksheets(2)
Dim ThisSQL
ThisSQL = "SELECT * "
Dim connString As String
connString = "TEXT;q:\arbeid\20040903.icm.95pc.dvf.txt"
Dim thisQT As QueryTable
Set thisQT = thisSheet.QueryTables.Add(Connection:=connString, Destination:=Range("A1"))
thisQT.BackgroundQuery = False
thisQT.TextFileCommaDelimiter = True
thisQT.TextFileParseType = xlDelimited
thisQT.TextFileStartRow = 3
thisQT.sql = ThisSQL
thisQT.Refresh
End Sub
The problem is that I get this error message: "Runtime Error '1004': Incomplete datasource"
What are the name of the tables/coloumns/fields in the text file I need to refer to in the Sql query?
With best regards,
M. Alexander Kleiven
Hello
I am trying to import selected data from a comma separated text file using the following method.
Sub PerformQuery()
Dim thisSheet As Worksheet
Set thisSheet = ThisWorkbook.Worksheets(2)
Dim ThisSQL
ThisSQL = "SELECT * "
Dim connString As String
connString = "TEXT;q:\arbeid\20040903.icm.95pc.dvf.txt"
Dim thisQT As QueryTable
Set thisQT = thisSheet.QueryTables.Add(Connection:=connString, Destination:=Range("A1"))
thisQT.BackgroundQuery = False
thisQT.TextFileCommaDelimiter = True
thisQT.TextFileParseType = xlDelimited
thisQT.TextFileStartRow = 3
thisQT.sql = ThisSQL
thisQT.Refresh
End Sub
The problem is that I get this error message: "Runtime Error '1004': Incomplete datasource"
What are the name of the tables/coloumns/fields in the text file I need to refer to in the Sql query?
With best regards,
M. Alexander Kleiven