Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2004
    Thanked 0 Times in 0 Posts

    Link text files with VBA (2000)

    I currently have a routine that loops through a series of text files (csv) by importing the text file with the DoCmd.TransferText command using a predefined file specification. After each file is imported into the current database, the procedure extracts the data and deletes the imported table. The problem I have is it takes awhile to import each file and the size of the database grows rather large. Is there a way to just link the text files using VBA instead of importing the file as a table?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 18 Times in 18 Posts

    Re: Link text files with VBA (2000)

    You could open a csv file, loop through its lines and process the data, then close the csv file. Fictitious example:

    Dim txtLastName As String
    Dim lngQuantity As Long
    Dim dtmOrderDate As Date
    Open "C:TestMyFile.csv" For Input As #1 ' Open file for input.
    Do While Not EOF(1) ' Loop until end of file.
    Input #1, txtLastName, lngQuantity, dtmOrderDate ' Read data into variables.
    ' Instructions to process data go here
    Close #1 ' Close file.

    Depending on the size of the file, this could be much slower than importing it. Another possibility is to open an ADO recordset on the csv file, and loop through its records.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Melbourne, Australia
    Thanked 23 Times in 23 Posts

    Re: Link text files with VBA (2000)

    Another option is to use the option Compact on Close.

Posting Permissions

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