'CopyFromRecordset' of object 'Range' failed

GreenyMcDuff

Active Member
Joined
Sep 20, 2010
Messages
313
Hi all,

Having a strange one here and can't find a solution on google.

I'm using an ADO object to pull data from an Oracle database.

My command object is set to open a recordset that gets populated from a stored procedure as follows:

Code:
    Dim cmd As New ADODB.Command:           Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = dbConnection
    cmd.Properties("PLSQLRSet") = True
    
    Dim param1 As New ADODB.Parameter
    Set param1 = cmd.CreateParameter("I_PORTF_CODE", adVarChar, adParamInput, Len("GBH-" & portfCode), "GBH-" & portfCode)
    cmd.Parameters.Append param1
    
    Dim param2 As New ADODB.Parameter
    Set param2 = cmd.CreateParameter("I_CONFIG_CODE", adVarChar, adParamInput, Len(configCode), configCode)
    cmd.Parameters.Append param2
    
    Dim param3 As New ADODB.Parameter
    Set param3 = cmd.CreateParameter("I_END_DATE", adDBDate, adParamInput, , endDate)
    cmd.Parameters.Append param3
    Dim param4 As New ADODB.Parameter
    Set param4 = cmd.CreateParameter("I_PERIOD", adVarChar, adParamInput, Len(period), period)
    cmd.Parameters.Append param4
    
    cmd.CommandText = "{CALL UD_MRT_ATTR_DATA_TEST(?,?,?,?)}"
    
    Dim resultsSet As ADODB.Recordset:      Set resultsSet = New ADODB.Recordset
    With resultsSet
        .ActiveConnection = dbConnection
        .CursorLocation = adUseClient
        .CursorType = adOpenDynamic
        .LockType = adLockOptimistic
        .Open cmd
    End With
    cmd.Properties("PLSQLRSet") = False
       
    Set GetATTRDataFromBOne = resultsSet
    Exit Function

This returns a recordset with 152 fields and 96 records. When the below line executes:

Code:
ws.Cells(2, 1).CopyFromRecordset rs

I get the error: 'CopyFromRecordset' of object 'Range' failed

The strange thing is, if I Debug and press F5 the code executes and continues successfully without displaying the error again.

This code works for 95% of the parameters I use which leads me to think there must be some constraints about what types of data you can populate a recordset with. If this is the case does anyone know what the constraints are?

Thanks
Chris
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,226,456
Messages
6,191,145
Members
453,643
Latest member
adamb83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top