ACC: How to Import Several dBASE Databases at Once 95/97

Last reviewed: August 29, 1997
Article ID: Q141611
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SUMMARY

This article demonstrates how you can import multiple dBASE databases using a batch process using Visual Basic for Applications.

Many new Microsoft Access 7.0 and 97 users want to immediately import data from the systems they are currently using. The Import dialog box in Microsoft Access enables you to import one table at a time, which usually is sufficient. However, some users have numerous tables to import, or they may want to import multiple tables regularly.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

MORE INFORMATION

You can quickly import tables with a batch process using a Visual Basic procedure and a batch table. This procedure is designed for importing only dBASE databases, but you can easily modify the procedure to accommodate other file formats.

The batch table lists the tables that you want to import. The Visual Basic procedure reads the table and imports each foreign table listed there. To do so, follow these steps:

  1. Create a table called Batch Import with the following structure:

          Table: Batch Import
          ----------------------------
          Field Name: Source Directory
    
             Data Type : Text
             Field Size: 50
          Field Name: Source Database
             Data Type : Text
             Field Size: 50
          Field Name: Imported Name
             Data Type : Text
             Field Size: 50
          Field Name: Type of Table
             Data Type : Text
             Field Size: 50
    
    

  2. Enter information in the new Batch Import table about the tables you want to import. The fields in the Batch Import table should be filled out as follows:

        - Source Directory: This is the full path for the location of the
          foreign database file (for example, C:\dBase).
    

        - Source Database: This is the name and extension of the dBASE
          database you want to import (for example, Customer.dbf).
    

        - Imported Name: This is the name you want the table to have once it
          is imported into Microsoft Access (for example, Customers).
    

        - Table Type: This can be either dBASE III or dBASE IV. Specify dBASE
          III for both dBASE III and dBASE III PLUS databases.
    

    For example, to import a dBASE IV database called Employee.dbf from the C:\dBase4 directory and a dBASE III database called Orders.dbf from the D:\dBase3\Data directory, you would fill out the fields in the Batch Import table as follows:

          Source Directory   Source Database  Imported Name   Table Type
          --------------------------------------------------------------
          C:\dBase4          Employee.dbf     Employee Table  dBASE IV
          D:\dBase3\data     Orders.dbf       Orders Table    dBASE III
    
    

  3. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  4. Type the following procedure:

          Function BatchImport() As Boolean
    
             On Local Error GoTo BatchImport_Err
             Dim MyDB As DATABASE, MyTbl As Recordset
             Set MyDB = CurrentDb()
             Set MyTbl = MyDB.OpenRecordset("Batch Import", dbOpenTable)
             DoCmd.Hourglass True
             MyTbl.MoveFirst
             Do Until MyTbl.EOF
                DoCmd.TransferDatabase acImport, _
                 MyTbl("Type of Table"), _
                 MyTbl("Source Directory"), _
                 acTable, _
                 MyTbl("Source Database"), _
                 MyTbl("Imported Name"), _
                 False
                MyTbl.MoveNext
             Loop
             MyTbl.Close
          BatchImport_End:
             DoCmd.Hourglass False
             Exit Function
          BatchImport_Err:
             MsgBox Err.Description
             Resume BatchImport_End
          End Function
    
    

  5. To test this function, type the following line in the Debug window, and then press ENTER.

             ?BatchImport()
    
       Note that the pointer becomes an hourglass and remains so until all of
       your databases are imported. This process may take several minutes,
       depending on the size of the databases.
    
    

REFERENCES

For more information about TransferDatabase, search the Help Index for "TransferDatabase method," or ask the Microsoft Access 97 Office Assistant.

For more information about batch importing dBASE databases in Microsoft Access version 1.x or 2.0, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q88764
   TITLE     : ACC: How to Import Several dBASE Databases at Once (1.x/2.0)

dBase III, dBASE III PLUS, and dBASE IV are manufactured by Borland International, Inc., a vendor independent of Microsoft; we make no warranty, implied or otherwise, regarding the performance or reliability of these products.
Keywords          : kb3rdparty PgmHowTo PgmObj PgmFilM
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.