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
Comment Utility
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

Comment Utility

   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

Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
" 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

Comment Utility
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
Comment Utility
< 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

Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now