Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Search Sample for Oracle-to-Excel extraction with CopyFromRecordset | Excel Discussion (Misc queries) | |||
Format data in Excel after using copyfromrecordset | Excel Discussion (Misc queries) | |||
Excel 2003 Macro Error - Runtime error 1004 | Excel Discussion (Misc queries) | |||
CopyFromRecordset does nothing | Excel Programming |