Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2004
    Posts
    5
    Thanks
    0
    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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 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
    ...
    Loop
    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.

  4. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,535
    Thanks
    0
    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
  •