Link to home
Start Free TrialLog in
Avatar of Laurence Martin
Laurence MartinFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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.

Cheers

Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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.
Hi,

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

 User generated image
Steps:

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

***note***
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
Next

'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
.EntireColumn.AutoFit
End With



oApp.Visible = True
oApp.UserControl = True

'Close the Database and Recordset
rs.Close
db.Close

'clean up any extraneous rows
oSheet.Range("K1:Z1000").Delete
End Sub

Open in new window

" 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...
Avatar of Laurence Martin

ASKER

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.  

ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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