P
Phillip Hall
Hi all,
I have and ODBC query which returns data from a PostgreSQL database which
works correctly when I use the Get ExternaL Data & MS Query approach.
I want to use the QueryTable object in VBA to so the same. This is so I can
parameterise my select statement
The following macro
Dim thisSheet As Worksheet
Set thisSheet = ThisWorkbook.Worksheets(1)
Dim sql
sql = "SELECT * FROM books"
Dim connString
connString = "ODBC;DSN=Booktown"
Dim thisQT As QueryTable
Set thisQT = thisSheet.QueryTables.Add(Connection:=connString,
Destination:=Range("a1"))
thisQT.BackgroundQuery = False
thisQT.sql = sql
thisQT.Refresh
Causes this error
Run-time error'1004'
Method 'Refresh' of object '_QueryTable' failed.
Does anyone know what might be wrong with my macro. I think it might be the
connString that needs work.
-Phillip
I have and ODBC query which returns data from a PostgreSQL database which
works correctly when I use the Get ExternaL Data & MS Query approach.
I want to use the QueryTable object in VBA to so the same. This is so I can
parameterise my select statement
The following macro
Dim thisSheet As Worksheet
Set thisSheet = ThisWorkbook.Worksheets(1)
Dim sql
sql = "SELECT * FROM books"
Dim connString
connString = "ODBC;DSN=Booktown"
Dim thisQT As QueryTable
Set thisQT = thisSheet.QueryTables.Add(Connection:=connString,
Destination:=Range("a1"))
thisQT.BackgroundQuery = False
thisQT.sql = sql
thisQT.Refresh
Causes this error
Run-time error'1004'
Method 'Refresh' of object '_QueryTable' failed.
Does anyone know what might be wrong with my macro. I think it might be the
connString that needs work.
-Phillip