[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CopyFromRecordset unable to handle fields with null

Posted on 2008-10-01
3
Medium Priority
?
902 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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

873 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