Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Apr 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Import (Access XP)

    Each month approximately seven text files are downloaded to the desktop. We would like to pull the text files into a table (one after the other). However, each month I do not know how many files I will have. What would be the best way to do this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Import (Access XP)

    If you can ensure that the text files will be the only files on the desktop or whatever folder you download them to, you can write code that loops through the text files in the folder and imports them one by one.

    It's best to import one of the tables manually, and to create an import specification for it (click Advanced... just before finishing the import, then click Save As...). You can use this specification in the code. the code could look like this:

    Dim strPath As String
    Dim strFile As String
    ' Name of the destination table.
    Const strTable = "tblImport"
    ' Name of the specification
    Const strSpecification = "Text Import Specification"

    ' Path containing the text files, including trailing backslash
    strPath = "C:MyFolder"

    strFile = Dir(strPath & "*.txt")
    ' Loop through the files
    Do While Not strFile = ""
    ' Import the text file
    DoCmd.TransferText acImportDelim, strSpecification, strTable, strPath & strFile, True
    ' And on to the next one
    strFile = Dir
    Loop

  3. #3
    Lounger
    Join Date
    Apr 2003
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Import (Access XP)

    Thank you!!! Your knowledge and presentation, as well as the code itself is exceptional.

    With appreciation,
    Dee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •