View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tim Williams Tim Williams is offline
external usenet poster
 
Posts: 1,588
Default SQL Server in VBA problem

Debug.Print your SQL and run it in a query tool: syntax looks odd...

Tim


wrote in message ups.com...
I can't seem to be able to retrieve data from temporary tables. Is
something missing from my code? I can select the top ten form the
table and can select it into the temp table #lb, but I get nothing when
I try to retrieve the data from the temp table. Can anyone help?

Sub EmailSQLs()

Dim qt As QueryTable

sqlstr = "select top 10 * into #lb from dim_email" + _
" select * from #lb"

connstring = _
"ODBC;DSN=test;UID=;PWD=;Database=Kpi"

With ActiveSheet.QueryTables.Add(Connection:=connstring ,
Destination:=Range("A1"), SQL:=sqlstr).Refresh
End With
End Sub