ACC2000: How to Automate Importing All Files in a Specific Folder

ID: Q198467


The information in this article applies to:
  • Microsoft Access 2000


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article shows you how you can automate importing all files of a particular type from a specific folder on your hard disk. Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

The following example runs a procedure from a command button on a form. The procedure uses an input box to prompt for the folder containing the files that you want to import. Then the code loops through all the files in the folder that you specify and imports them all.

NOTE: The following example imports dBASE version 3.0 files. You select the file type that you want to import by changing the second argument of the TransferDatabase method. If you want to see a list of file types that you can import by using TransferDatabase, create a new macro and insert the TransferDatabase action. Then view the list of file types under the Database Type argument. When you are finished, close the macro without saving it.

  1. Create a new form not based on any table or query in Design view.


  2. Add a command button to the form and set its OnClick property to the following event procedure:


  3. 
    Private Sub Command0_Click()
    Dim InputDir, ImportFile As String, tblName As String
    Dim InputMsg as String
    
    InputMsg = "Type the pathname of the folder that contains "
    InputMsg = InputMsg & "the files you want to import."
    InputDir = InputBox(InputMsg)
    ' Change the file extension on the next line for the
    ' type of file you want to import.
    ImportFile = Dir(InputDir & "\*.dbf")
    
    Do While Len(ImportFile) > 0
       ' Use the import file name without its extension as the table
       ' name.
       tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1))
       ' Change dBase III on the next line to the type of file you
       ' want to import.
       DoCmd.TransferDatabase acImport, "dBase III", InputDir, _
             acTable, ImportFile, tblName
       ImportFile = Dir
    Loop
    End Sub
     
  4. Open the form in Form view and click the button to begin importing tables.



REFERENCES

For more information about the TransferDatabase method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "TransferDatabase method" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: programming directory

Keywords : kbdta AccCon IsmHowto PgmObj KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.