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.

Open table as spreadsheet

Parameter

Description

TransferType

Type of transfer to be performed. Valid choices are acImport (default), acLink, and acExport.

SpreadsheetType

Type of spreadsheet. The default is acSpreadsheet TypeExcel12Xml. See the help documentation for a complete list and explanation.

TableName

String expression that contains a table name or a SQL statement if you want to export data based on a SQL statement.

FileName

File name and path of your spreadsheet.

HasFieldNames

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

Range

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

UseOA

Optional 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 e-mail or send it to a colleague. The following code will create a new spreadsheet called Employees.xls in the temp directory.

 DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, _     "tblEmployees", "C:\Temp\Employees.xlsx"

An example of the spreadsheet created from the preceding command might look like the one shown in Figure 7-3.

image from book
Figure 7-3

Tip 

You can also use ADO to select, insert, update, and delete the underlying data in most of the data sources in this chapter by specifying the correct ADO provider (in this case Excel).




Beginning Access 2007 VBA
Beginning Access 2007 VBA
ISBN: 0470046848
EAN: 2147483647
Year: 2004
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net