View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default SQL Server in VBA problem

I would guess a querytable can only function on an SQL statement that
returns a single recordset. but assuming that is wrong, I doubt the correct
syntax for multiple SQL statements is like that.
You need the temp table ?

NickHK

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