What are the relative merits of OutputTo and TransferSpreadsheet?

Posted on 2011-09-14
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
LVL 84
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

776 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