Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel 2003 - 'CopyFromRecordset' Error

I have some VBA code that uses an ADO connection to query a SQL
server. It works fine under Office 2000, Office XP, but fails in
Office 2003.

I am receiving the following error message:

Method 'CopyFromRecordset' of object 'Range' failed.

Here is a snippet of my VBA code:

'' Initialize variables.
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String

cn.Open DBConnectionString ''DBConnectionString is declared in
module

strSQL = "SQL code here..."

Set rs = cn.Execute(strSQL)

''Clear old values
Me.Range("rngData").ClearContents

If Not rs.EOF Then
''Dump contents of recordset onto worksheet
Sheet001.Range("Data_Start").CopyFromRecordset rs

rs.Close

Else
MsgBox "Error: No records returned.", vbCritical
End If

ExitMethod:
cn.Close
Set rs.ActiveConnection = Nothing

Exit Sub

ErrorHandler:
MsgBox Err.Description

Exit Sub

End Sub


Any help would be appreciated. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel 2003 - 'CopyFromRecordset' Error


I use 2003 and have used the same code (which worked). I tried t
duplicate your error using the exact same string and all worked fine.
The only way I could duplicate it was to mis-type the Data_Start. I
it possible that there is no Data_Start range defined?



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26551

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel 2003 - 'CopyFromRecordset' Error

kkknie wrote in message ...
I use 2003 and have used the same code (which worked). I tried to
duplicate your error using the exact same string and all worked fine.
The only way I could duplicate it was to mis-type the Data_Start. Is
it possible that there is no Data_Start range defined?

K


Well I don't believe so because I can open up the same spreadsheet on
my other PC (Office 2000) just fine. I even tested it on another PC
running Office XP in our company.
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
Search Sample for Oracle-to-Excel extraction with CopyFromRecordset Keith Clark Excel Discussion (Misc queries) 0 January 22nd 09 07:31 PM
Format data in Excel after using copyfromrecordset jj Excel Discussion (Misc queries) 2 June 13th 07 06:48 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
CopyFromRecordset does nothing Hafeez Excel Programming 2 August 13th 04 07:20 PM


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

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"