7.4. Spreadsheets

The TransferSpreadsheet method is very similar to the TransferDatabase method in that it enables you to import, link, and export, only in this case it deals with spreadsheets. The syntax is shown in the following code:

DoCmd.TransferSpreadsheet TransferType, SpreadsheetType, TableName, FileName, HasFieldNames, Range, UseOA

Various parameters are used to specify how the method should execute. The following table explains the use of each parameter.

ParameterDescription
TransferTypeType of transfer to be performed. Valid choices are acImport (default), acLink, and acExport.
SpreadsheetTypeType of spreadsheet. The default is acSpreadsheet TypeExcel12Xml. See the help documentation for a complete list and explanation.
TableNameString expression that contains a table name or a SQL statement if you want to export data based on a SQL statement.
FileNameFile name and path of your spreadsheet.
HasFieldNamesUse True to use the first row of the spreadsheet as field names and False to treat the first row as data. False is the default.
RangeValid range of cells or named range in the spreadsheet that you want to import from. Leave blank to import an entire spreadsheet. Using with Export will cause an error.
UseOAOptional variant.

Now we'll walk through an example of how you might use the TransferSpreadsheet method to export data to a spreadsheet. Suppose that you want to export the contents of the Employees table you just imported from Northwind into a spreadsheet so that you can ...

Get Beginning Access™ 2007 VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.