LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default SQL Query to Excel

I am in the initial throws of attempting to populate an Excel Worksheet, with
table rows selected from a SQL Server DB, using the following code:

Sub WSPopulate()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strWhere As String

Set con = New ADODB.Connection
con.Open "Driver={SQL Server};Server=GVS00534\node1;Database=mydb;"
strWhere = "SELECT * FROM dbo.application WHERE Owner_L2 = 'sbcorg'"

Set rs = con.Execute(strWhere, , 1)
Range("a1").CopyFromRecordset rs

rs.Close
con.Close
End Sub

This worked VERY nicely the first time...and ALL my data rows/columns
populated the page. However, on my second attempt, only 3 columns from the
sql db passed to the Worksheet, and on my 3rd, nothing. On the third try,
the hour glass hardly flickered...it's as if I have consumed all of some
resource along the way. Do I have a "hygiene" issue here, where I am not
releasing something I should be? Any other ideas? Also, does anyone have a
pointer to tips on how to do this? I am pretty new to DB access from excel
VBA, and some "examples" might help me a lot.

Thanks,
Patk
 
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
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 0 November 28th 05 06:37 PM
Edit Query from Excel will not open query in MSQuery Michelle Excel Programming 0 February 21st 05 03:59 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 08:53 PM.

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

About Us

"It's about Microsoft Excel"