Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jfs jfs is offline
external usenet poster
 
Posts: 2
Default QueryTable connection using ADO Recordset

I have the following code snippet to transfer the results of a SQL Server
2000 sp to an Excel Sheet:

Dim Newcn as new adodb.connection
Dim oQueryTable As Excel.QueryTable

Newcn.CommandTimeout = 0
Newcn.ConnectionString = ConnString ' Connection string passed into this
procedure
Newcn.Open
Newcn.Errors.Clear

' Create a record set with the results from the stored proc
Set rs = New ADODB.Recordset

rs.Open QueryString, Newcn, adOpenStatic, adLockOptimistic

Set oExcel = CreateObject("Excel.Application")

Set oBook = oExcel.Workbooks.Open(ExportTo)

Set osheet = oBook.Worksheets(TabName)

'Transfer the data to Excel

osheet.Activate
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,
Destination:=oExcel.ActiveSheet.Range("A1"))

When it attempts to add the querytable, I get the following error:

Error number 5
Invalid procedure call or argument

I have tried using an OLEDB connection to add the Querytable which works,
but when I attempt to refresh it with the stored procedure as the
commandtext, I get "The Query did not run, or the database table could not be
opened."

I have checked access permissions in SQL and all is well - the sp will run
from Query Analyzer.

Any insight would be most welcome.
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default QueryTable connection using ADO Recordset

Do you need to create another instance of Excel ?

You seems to be confusing yourself which instance you are working with.

'Created instance
osheet.Activate

'This instance - no oExcel qualifier
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,

'Created instance
Destination:=oExcel.ActiveSheet.Range("A1"))

NickHK


"jfs" wrote in message
...
I have the following code snippet to transfer the results of a SQL Server
2000 sp to an Excel Sheet:

Dim Newcn as new adodb.connection
Dim oQueryTable As Excel.QueryTable

Newcn.CommandTimeout = 0
Newcn.ConnectionString = ConnString ' Connection string passed into this
procedure
Newcn.Open
Newcn.Errors.Clear

' Create a record set with the results from the stored proc
Set rs = New ADODB.Recordset

rs.Open QueryString, Newcn, adOpenStatic, adLockOptimistic

Set oExcel = CreateObject("Excel.Application")

Set oBook = oExcel.Workbooks.Open(ExportTo)

Set osheet = oBook.Worksheets(TabName)

'Transfer the data to Excel

osheet.Activate
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,
Destination:=oExcel.ActiveSheet.Range("A1"))

When it attempts to add the querytable, I get the following error:

Error number 5
Invalid procedure call or argument

I have tried using an OLEDB connection to add the Querytable which works,
but when I attempt to refresh it with the stored procedure as the
commandtext, I get "The Query did not run, or the database table could not

be
opened."

I have checked access permissions in SQL and all is well - the sp will run
from Query Analyzer.

Any insight would be most welcome.
Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
jfs jfs is offline
external usenet poster
 
Posts: 2
Default QueryTable connection using ADO Recordset

Honestly, those details don't matter - no, its not invoking another instance
of Excel. I read somewhere that the Destination parameter needs EXPLICIT
instructions on the sheet name. The issue I'm having is that I cannot
refresh the querytable once its defined. Can anyone help with this.

Thanks.


"NickHK" wrote:

Do you need to create another instance of Excel ?

You seems to be confusing yourself which instance you are working with.

'Created instance
osheet.Activate

'This instance - no oExcel qualifier
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,

'Created instance
Destination:=oExcel.ActiveSheet.Range("A1"))

NickHK


"jfs" wrote in message
...
I have the following code snippet to transfer the results of a SQL Server
2000 sp to an Excel Sheet:

Dim Newcn as new adodb.connection
Dim oQueryTable As Excel.QueryTable

Newcn.CommandTimeout = 0
Newcn.ConnectionString = ConnString ' Connection string passed into this
procedure
Newcn.Open
Newcn.Errors.Clear

' Create a record set with the results from the stored proc
Set rs = New ADODB.Recordset

rs.Open QueryString, Newcn, adOpenStatic, adLockOptimistic

Set oExcel = CreateObject("Excel.Application")

Set oBook = oExcel.Workbooks.Open(ExportTo)

Set osheet = oBook.Worksheets(TabName)

'Transfer the data to Excel

osheet.Activate
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,
Destination:=oExcel.ActiveSheet.Range("A1"))

When it attempts to add the querytable, I get the following error:

Error number 5
Invalid procedure call or argument

I have tried using an OLEDB connection to add the Querytable which works,
but when I attempt to refresh it with the stored procedure as the
commandtext, I get "The Query did not run, or the database table could not

be
opened."

I have checked access permissions in SQL and all is well - the sp will run
from Query Analyzer.

Any insight would be most welcome.
Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default QueryTable connection using ADO Recordset

What do you think this line means ?
Set oExcel = CreateObject("Excel.Application")


NickHK

"jfs" wrote in message
...
Honestly, those details don't matter - no, its not invoking another

instance
of Excel. I read somewhere that the Destination parameter needs EXPLICIT
instructions on the sheet name. The issue I'm having is that I cannot
refresh the querytable once its defined. Can anyone help with this.

Thanks.


"NickHK" wrote:

Do you need to create another instance of Excel ?

You seems to be confusing yourself which instance you are working with.

'Created instance
osheet.Activate

'This instance - no oExcel qualifier
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,

'Created instance
Destination:=oExcel.ActiveSheet.Range("A1"))

NickHK


"jfs" wrote in message
...
I have the following code snippet to transfer the results of a SQL

Server
2000 sp to an Excel Sheet:

Dim Newcn as new adodb.connection
Dim oQueryTable As Excel.QueryTable

Newcn.CommandTimeout = 0
Newcn.ConnectionString = ConnString ' Connection string passed into

this
procedure
Newcn.Open
Newcn.Errors.Clear

' Create a record set with the results from the stored proc
Set rs = New ADODB.Recordset

rs.Open QueryString, Newcn, adOpenStatic, adLockOptimistic

Set oExcel = CreateObject("Excel.Application")

Set oBook = oExcel.Workbooks.Open(ExportTo)

Set osheet = oBook.Worksheets(TabName)

'Transfer the data to Excel

osheet.Activate
Set oQueryTable = ActiveSheet.QueryTables.Add(Connection:=rs,
Destination:=oExcel.ActiveSheet.Range("A1"))

When it attempts to add the querytable, I get the following error:

Error number 5
Invalid procedure call or argument

I have tried using an OLEDB connection to add the Querytable which

works,
but when I attempt to refresh it with the stored procedure as the
commandtext, I get "The Query did not run, or the database table could

not
be
opened."

I have checked access permissions in SQL and all is well - the sp will

run
from Query Analyzer.

Any insight would be most welcome.
Thanks.






Reply
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
ADO Connection vs Recordset objects. DaveO Excel Programming 3 July 12th 06 02:43 PM
Querytable results into vba Recordset Aaron Excel Programming 3 September 19th 05 10:13 AM
Populate QueryTable Using SQL Server - Connection Problem AMIT Excel Programming 1 September 7th 05 09:34 AM
querytable connection TxRaistlin Excel Programming 2 February 9th 05 01:49 PM
Find the contents of a Connection property of the QueryTable objec SPYREN Excel Programming 4 October 28th 04 04:03 PM


All times are GMT +1. The time now is 04:56 PM.

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"