Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2007 / MS Query - editing existing query to another sheet | Excel Discussion (Misc queries) | |||
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? | Excel Discussion (Misc queries) | |||
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? | Excel Discussion (Misc queries) | |||
Edit Query from Excel will not open query in MSQuery | Excel Programming | |||
How to use a Access Query that as a parameter into Excel database query | Excel Discussion (Misc queries) |