P
PatK
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
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