Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Thanked 0 Times in 0 Posts

    Automated import of .csv files (2002)

    There are several .csv files that get imported daily that currently require unnecessary user input. These are small files and are of two standard types. Currently the users select the import file from a form and clicks on a button that executes some VBA that accomplished the import. I'd like to have a process that runs whenever the database is open that monitors a folder and then runs the import function on any file copied into that folder. Any suggestions and/or examples of how I could accomplish this?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Melbourne, Australia
    Thanked 27 Times in 27 Posts

    Re: Automated import of .csv files (2002)

    I would tend to create a new form. All it would do is awaken every couple of minutes via the timer.
    It would check the folder in question, import any files that it needs to and goes back to sleep for a few minutes.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Automated import of .csv files (2002)

    You could use code like this:

    Function HandleFolder()
    ' Path must end in backslash
    Const strPath = "C:Test"
    Dim strFile As String

    strFile = Dir(strPath & "*.csv")
    Do While Not strFile = ""
    HandleFile strPath & strFile
    strFile = Dir
    End Function

    Function HandleFile(strFullname As String)
    ' Import text file here
    End Function

    If you have a startup form in your database, you can call HandleFolder from the On Open or On Load event of this form.
    Otherwise, you can create a macro named AutoExec (it must be exactly named like that) and use the RunCode command to call the HandleFolder function.
    The AutoExec macro will be executed automatically when the database is opened.

    If you want to open the database without the startup form being opened or the AutoExec macro being executed, hold down Shift while opening the database.

Posting Permissions

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