LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SQL Server in VBA problem

Thanks for the help everyone! I figured out the answer to my problem
and figured I'd post it for future reference :)

Only using 1 # in #topten creates a local temp table and I needed to
create a global temp table by using ##topten. The local worked in SQL
server because I was using it within the same query window, but it
seems that submitting it through VBA submits it as if it were two
different query windows.

Also, this modified version of the code below worked. I'm sure
there's a cleaner version of the code to use, but this did work.

Sub EmailSQL3()
Dim qt As QueryTable

sqlstr = "select top 10 * into ##topten from dim_emailtemplete"

connstring = _
"ODBC;DSN=test;UID=;PWD=;Database=Kpirepositor y"

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

sqlstr = "select top 10 * from ##topten"

connstring = _
"ODBC;DSN=test;UID=;PWD=;Database=Kpirepositor y"

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

End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem updating link from Novell server to windows server #REF er Ellen Excel Discussion (Misc queries) 0 May 10th 05 09:18 PM
ADO connection problem when using server Bkraska Excel Programming 7 March 18th 05 02:15 PM
query problem after changing to SQL server Margaret Excel Discussion (Misc queries) 1 December 13th 04 11:23 AM
Problem linking with SQL Server Paul Ingles[_2_] Excel Programming 0 September 8th 03 06:15 PM
Problem linking with SQL Server Paul Ingles Excel Programming 0 September 8th 03 04:55 PM


All times are GMT +1. The time now is 06:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"