ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Importing Data from a Stored Procedure (SQL SErver) (https://www.excelbanter.com/excel-programming/288658-importing-data-stored-procedure-sql-server.html)

Martin Eckart

Importing Data from a Stored Procedure (SQL SErver)
 
Hi there,

I am trying to import data from a Stored procedure which has a Select
Statement in it into Excel.
I could also exec the select Statement out of Excel (VBA), that would be ok
for me also.

I am struggling in setting up the Connection and the Recordset Objects and
then call the CopyfromRecordset method.

For example:
I have in my code:
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection

and I get the following Error while running the Macro: Compile Error:
User-Defined type not defined

I have to admit that I am not that good in ADODB Connection building and
Recordset operations...

I would appreciate your help big time.

Thanks,
Martin



Robin Hammond[_2_]

Importing Data from a Stored Procedure (SQL SErver)
 
Martin,

the error you are getting suggests that you haven't set a reference to ado.
You want to get the latest MDAC version from MS
http://www.microsoft.com/downloads/d...displaylang=en

there was also an update put out by MS on the 13th patching a security flaw.
I can't find the link, but try windows update..

In your VBA project, make sure you have a reference set to ms activex data
objects 2.7 library. On my system the file resides in c:\program
files\common files\ado\msado27.tlb.

If you are looking for general information on using ado with excel, the best
I have found so far is in Excel 2002 VBA by Stephen Bullen et al.

Robin Hammond
www.enhanceddatasystems.com


"Martin Eckart" wrote in message
...
Hi there,

I am trying to import data from a Stored procedure which has a Select
Statement in it into Excel.
I could also exec the select Statement out of Excel (VBA), that would be

ok
for me also.

I am struggling in setting up the Connection and the Recordset Objects and
then call the CopyfromRecordset method.

For example:
I have in my code:
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection

and I get the following Error while running the Macro: Compile Error:
User-Defined type not defined

I have to admit that I am not that good in ADODB Connection building and
Recordset operations...

I would appreciate your help big time.

Thanks,
Martin






All times are GMT +1. The time now is 08:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com