Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Excel CopyFromRecordset issue

Posted on 2010-08-26
7
664 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:KingstonDeveloper
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33535247
KingstonDeveloper,The maximum number of characters in a single cell is 32,767.  Any chance you have a string longer than that?Patrick
0
 

Author Comment

by:KingstonDeveloper
ID: 33535782
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
0
 

Author Comment

by:KingstonDeveloper
ID: 33535935
Okay, I have a result with 2400 chars and it still fails.
However, I got one that works with 896 chars.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33535954
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?
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 33536107
OK, found the limit: it's 911 characters.  Seems that this is peculiar to Excel 2003, and not a problem with other versions.http://support.microsoft.com/kb/818808/en-usI am afraid that you'll have to loop through the recordset row by row, column by column and put the values in that way.  Inefficient and slow, but should work.Not sure what it looks like in ASP, but in VBA...
DestRow = 1
Do Until rs.EOF
    With 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

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33536138
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

Open in new window

0
 

Author Closing Comment

by:KingstonDeveloper
ID: 33537919
Thanks Matt. Looks like I will have to do the loop...Yikes
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question