KingstonDeveloper
asked on
Excel CopyFromRecordset issue
Hello,
I'm using Excel automation in a DCOM for my classic asp application and I am getting "Access Denied" error when one of the columns from the recordset has a very long string. I found that out when I change my Select statement to retrieve different date range and one of the result contained a long string. I am not able to find out what is the limit length of the Cell in MS automation object. However, I can put a very long string (10000 chars) in a interactive Excel sheet. This is happening in Excel 2003
My question is how to overcome this with minimal code change? The same function is still working under Excel 2000.
Thank you.
I'm using Excel automation in a DCOM for my classic asp application and I am getting "Access Denied" error when one of the columns from the recordset has a very long string. I found that out when I change my Select statement to retrieve different date range and one of the result contained a long string. I am not able to find out what is the limit length of the Cell in MS automation object. However, I can put a very long string (10000 chars) in a interactive Excel sheet. This is happening in Excel 2003
My question is how to overcome this with minimal code change? The same function is still working under Excel 2000.
Thank you.
KingstonDeveloper,The maximum number of characters in a single cell is 32,767. Any chance you have a string longer than that?Patrick
ASKER
Hi Matt,
Thanks for the quick response. I run the query in the Query Analyzer and the string I get from this is only a little less than 3000 chars (include spaces).
Thanks again
Thanks for the quick response. I run the query in the Query Analyzer and the string I get from this is only a little less than 3000 chars (include spaces).
Thanks again
ASKER
Okay, I have a result with 2400 chars and it still fails.
However, I got one that works with 896 chars.
However, I got one that works with 896 chars.
I found an old thread at MrExcel in which it appears that using CopyFromRecordset is problematic when you have a text field exceeding 255 characters:http://www.mrexcel.com/forum/showthread.php?t=160922If you alter yur recordset construction so that it only gets the first 255 characters, i.e., Left(SomeColumn, 255), does it work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assuming that this problem is specific to Excel 2003 (it seems to be)...
If xlApp.Version = 11 Then
DestRow = 1
Do Until rs.EOF
With xlApp.ActiveSheet
For ColumnCounter = 1 To rs.Fields.Count
If DestRow > 1 Then
.Cells(DestRow, ColumnCounter) = rs.Fields(ColumnCounter - 1).Value
Else
.Cells(DestRow, ColumnCounter) = rs.Fields(ColumnCounter - 1).Name
End If
Next
End With
DestRow = DestRow + 1
rs.MoveNext
Loop
Else
With xlApp.ActiveSheet
For ColumnCounter = 1 To rs.Fields.Count
.Cells(DestRow, ColumnCounter) = rs.Fields(ColumnCounter - 1).Name
Next
.Cells(2, 1).CopyFromRecordset rs
End With
End If
ASKER
Thanks Matt. Looks like I will have to do the loop...Yikes