What are the relative merits of OutputTo and TransferSpreadsheet?

Posted on 2011-09-14
Medium Priority
Last Modified: 2012-05-12
I am developing an Access front-end on a SQL Server database and need to get data out into Excel.

I am finding OutputTo very slow to produce the 11 thousand records.  But it gets there in the end.

TransferSpreadsheet is much faster (Why?) but seems to be less reliable.  It seems to be that if the destination spreadsheet has anything in it that the export doesn't expect, it crashes.  Also, you have to have extra code to open the spreadsheet afterwards.

Up to now I've been using OutputTo, but am wondering whether TransferSpreadsheet would be better if we can prevent the crashes.  But, how to prevent the crashes?

I'm interested in what I should know about the two methods and if one is preferable to the other.


Question by:LJKMartin
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
LVL 85
ID: 36541891
If I had to hazard a guess, I would think the performance would result from:

OutputTo requires the Access UI to render something onscreen (even if you do it hidden, it's still rendered), whereas TransferSpreadsheet deals with data only.

I've not really had any crashes using these methods, but then I've never tried to export 11k records to a spreadsheet. Given that you're on a SQL Server backend, you might consider using SSIS to export your data. You can build an SSIS package and then use standard commandline calls via Shell to "call" that package.
LVL 11

Expert Comment

ID: 36542033

   i think the problem with the Excel file .... can you please refer my attachd example.


1 create a new Excel template and save in a shared path .
2. do the above steps

FST_Copy: It will create a new file from the existing template .

Note : it will note affect your existing template .....  
LVL 26

Expert Comment

ID: 36543930
I personally go at it the other way around.
I open Excel from Access VBA code and use CopyFromRecordset.
This is quick and bulletproof once it is debugged.
And it leaves the spreadsheet open and in user control when it's done.

This code runs in Access, and I have a reference set to the Excel X.0 object library
Private Sub cmdExcelFleetSummary_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = Me.RecordsetClone

'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet

Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets(1)

'Add the field names in row 1
Dim i As Integer
Dim iNumCols As Integer
'iNumCols = 9
iNumCols = rs.Fields.count
For i = 1 To iNumCols
oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name

'Add the data starting at cell A2
oSheet.Range("A2").CopyFromRecordset rs

'Format the header row as bold and autofit the columns
With oSheet.Range("a1").Resize(1, iNumCols)
.Font.Bold = True
End With

oApp.Visible = True
oApp.UserControl = True

'Close the Database and Recordset

'clean up any extraneous rows
End Sub

Open in new window

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36544426
" It seems to be that if the destination spreadsheet has anything in it that the export doesn't expect, it crashes."
Then clean the data before the operation...
In other words, see what is causing the crash, ...and set the producer that creates the data to deal with this.
Since you only use a very generic term "Crash", you will need to be more specif here...

With OutputTo, you can actually open the just created file using the "AutoStart" argument
With TransferSpreadshhet you can easily specify a Range of cells and if the target has Field names.

But if you really need a comparison of the two, all you have to do is see the help files for each.
Everything you could ever want and more is listed there...

Author Comment

ID: 36549850
Thanks for all your responses.

I'll definately look at SSIS.  I would have thought creating a stored procedure will help too, but if the delay is due to rendering, I guess that's not going to make much difference.  OutputTo renders the data however it's been generated.

Thanks Nick67 for recommending another way.  I'll give it go.

Boag2000 - it's not the data that's causing the crashes so it doesn't matter whether it's clean or not.  If the user edits the destination spreadsheet and saves the changes, the next time they run the TransferSpreadsheet the process crashes.  The Help file doesn't tell me about that!  It also doesn't tell me what LSMConsulting has said about rendering. The Help files will always be limited  in their use(otherwise we wouldn't need great sites like this).   My main question is when to use TransferSpreadsheet and when OutputTo which the Help doesn't discuss.  

LVL 74

Accepted Solution

Jeffrey Coachman earned 1500 total points
ID: 36550596
< If the user edits the destination spreadsheet and saves the changes>
The standard approach is to import into a spreadsheet template, not a standard workbook.
This will sidestep this issue.
See here:

The "rendering" issue is mentioned in the help files, but not explained completely though...
(OutputQuality, ...ect)

The main difference between Outputo and Transfer spreadsheet is that Output to can be used to output almost any Access object to a variety of formats.
As it's name implies, this can only be used to "Output" objects.

Transferspreadsheet, as it's name implies, is only designed to transfer to *and* from Excel formats.
So in a general sense, if your primary focus will be on transferring data to and from Excel,  then I would go with TransferSpreadsheet.


Author Closing Comment

ID: 36567743
Thank-you for the point about importing into a template.

I've been using OutputTo because it's easier to open the resulting file, but I will go with TransferSpreadsheet from now on.

The fact that an 'Output' and a 'Transfer' are intrinsically different is news to me I'm afraid.

Thanks again

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

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