?
Solved

CopyFromRecordset unable to handle fields with null

Posted on 2008-10-01
3
Medium Priority
?
876 Views
Last Modified: 2013-11-29
Method 'CopyFromRecrodset' of ojbect 'Range' failed.  If I remove fields containing null values, this code works.  The data recordset can and will have fields with a null values is there a workaround?  I really need a quick method to export a large recordset to Excel.

   
CellCnt = 1
        For Each fld In rs.Fields
               xlSheet.Cells(1, CellCnt).Value = fld.Name
               xlSheet.Cells(1, CellCnt).Interior.ColorIndex = 33
               xlSheet.Cells(1, CellCnt).Font.Bold = True
               xlSheet.Cells(1, CellCnt).BorderAround xlContinuous
               CellCnt = CellCnt + 1
        Next fld
    
        rs.MoveFirst
        xlSheet.Cells(2, 1).CopyFromRecordset rs
        DoEvents
 
    ' Auto fit columns.
        xlSheet.Cells.EntireColumn.AutoFit
        xlSheet.Cells.Select
        xlSheet.Cells.AutoFilter

Open in new window

0
Comment
Question by:tipvernonia
[X]
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
  • 2
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 22617476

you will need to individually fill out the cells with the specific  rs.fields value

             xlSheet.Cells(2, 1).value=nz(rs("fieldname"),"")  '< for text field
0
 

Author Comment

by:tipvernonia
ID: 22623877
I already used this method.  I was looking for a faster method.  When there are 10,000 row with 28 columns this method is very slow.  
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1500 total points
ID: 22625004
try using the nz function in the query for the field that has null values
use the query for the recordset and use the copyfromrecordset to fill the excel file with values
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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