Importing and Exporting Text File Data in VBA Code..............................................
The main menu of the sample application, External Data.accdb (shown in Figure 10.10), has but-
tons for opening various forms that import and export data in a variety of file formats. Writing VBA
code to do the imports and exports gives you one-click convenience, particularly useful if you have
to do an import or export task frequently, for example importing weekly Jobs data downloaded
from a mainframe computer or emailed as a fixed-width or comma-delimited text file.
FIGURE 10.10
The main menu of the External Data sample database.
Importing Text Data ......................................................................................
The following steps illustrate how to import data from a text file into an Access table, using VBA
code running from controls on an Access form (frmImportTextData, illustrated in Figure 10.11):
- Selecting the “Import Data from Text Files” option and clicking the button to its left opens
the Import Job Data from Text File (frmImportTextData) form, as shown in Figure 10.11.
If a text file was previously selected, its name is displayed in the textbox to the right of
the “Source Text File” button. - You can use the selected file (if one is listed), or you can select another by clicking the
“Source Text File” button, which opens a File Picker dialog box. The File Picker dialog
box is filtered to display either comma-delimited (.csv) or fixed-width (.txt) files, accord-
ing to the option selected in the Import Text Type option group. In Figure 10.12, I’ve
selected a comma-delimited text file for import.
Part II Writing VBA Code to Exchange Data between Office Components