What are the relative merits of OutputTo and TransferSpreadsheet?

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.


Who is Participating?
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:
< 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.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
SThayaTechnical MAnagerCommented:

   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 .....  
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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

Jeffrey CoachmanMIS LiasonCommented:
" 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...
LJKMartinAuthor Commented:
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.  

LJKMartinAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.