TransferText Action

Description

You can use the TransferText action to import or export text between the current Microsoft Access database and a text file. You can also link the data in a text file to the current Microsoft Access database. With a linked text file, you can view and edit the text data with Microsoft Access while still allowing complete access to the data from your word processing program.

Setting

The TransferText action uses the following arguments.

Action argument

Description

Transfer Type

The type of transfer you want to make. You can import data from, export data to, or link to data in delimited or fixed-width text files. You can also export data to a Microsoft Word for Windows mail merge data file, which you can then use with the Word for Windows mail merge feature to create merged documents such as form letters and mailing labels.

Select Import Delimited, Import Fixed Width, Export Delimited, Export Fixed Width, Link Delimited, Link Fixed Width, or Export Word for Windows Merge in the Transfer Type argument in the Action Arguments section of the Macro window. The default is Import Delimited.

Specification Name

The specification name for the set of options that determines how a text file is imported, exported, or linked. This is a required argument for fixed-width text files.

You can use the Import or Link Tables subcommand of the Get External Data command or the Save As/Export command on the File menu to create a specification for a particular type of text file, such as a delimited text file that uses tabs to separate fields and has an MDY format for dates. When you click one of these commands and select a type of text file to import, export, or link, the Text Import Wizard, Text Export Wizard, or Link Text Wizard runs. You can click the Advanced button in the wizard and define and save a specification in the dialog box that is displayed. You can then type the specification name in this argument whenever you want to import or export the same type of text file.

You can import, export, or link delimited text files without typing a specification name for this argument. In this case, Microsoft Access uses the defaults from the wizard dialog box. Microsoft Access uses a predetermined format for mail merge data files, so you don’t ever need to type a specification name for this argument when you export these types of files.

Table Name

The name of the Microsoft Access table to import text data to, export text data from, or link text data to. You can also type the name of the Microsoft Access select query you want to export data from. This is a required argument.

If you click Import Delimited or Import Fixed Width in the Transfer Type box, Microsoft Access appends the text data to this table if the table already exists. Otherwise, Microsoft Access creates a new table containing the text data.

File Name

The name of the text file to import from, export to, or link to. Include the full path. This is a required argument.

Microsoft Access creates a new text file when you export data from Microsoft Access. If the filename is the same as the name of an existing text file, Microsoft Access replaces the existing text file.

Has Field Names

Specifies whether the first row of the text file contains the names of the fields. If you click Yes, Microsoft Access uses the names in this row as field names in the Microsoft Access table when you import or link the text data. If you click No, Microsoft Access treats the first row as a normal row of data. The default is No.

Microsoft Access ignores this argument for Word for Windows mail merge data files because the first row must contain the field names.

When you export Microsoft Access table or select query data to a delimited or fixed-width text file, Microsoft Access inserts the field names of your table or select query into the first row of the text file if you have selected Yes for this argument.

If you are importing or linking a fixed-width text file and click Yes in this box, the first row containing the field names must use the field delimiter set in the import/export specification to separate the field names. If you are exporting to a fixed-width text file and click Yes for this argument, Microsoft Access inserts the field names into the first row of the text file using this delimiter.


Remarks

You can export the data in Microsoft Access select queries to text files, as long as these select queries don’t contain parameters. Microsoft Access exports the result set of the query, treating it just like a table.

Text data that you append to an existing Microsoft Access table must be compatible with the table’s structure. Each field in the text must be of the same data type as the corresponding field in the table, and the fields must be in the same order (unless you set the Has Field Names argument to Yes, in which case the field names in the text must match the field names in the table).

Note This action is similar to clicking the Import or Link Tables subcommand of the Get External Data command or the Save As/Export command on the File menu of the Database window. You can use these commands to select a source of data, such as Microsoft Access or a type of database, spreadsheet, or text file. If you select a delimited or fixed-width text file, a wizard prompts you to select the name of the text file and other options. The arguments of the TransferText action reflect the options in these wizards.

An import/export specification stores the information Microsoft Access needs to import, export, or link a text file. You can use stored specifications to import, export, or link text data from or to similar text files. For example, you might receive weekly sales figures in a text file from a mainframe computer. You can create and save a specification for this type of data and then use the specification whenever you add this data to your Microsoft Access database.

To run the TransferText action in Visual Basic, use the TransferText method of the DoCmd object.

See Also

OutputTo Action, SendObject Action, TransferDatabase Action, TransferSpreadsheet Action, TransferText Method.